|
| 1 | +# Script Include for Single Sign-On (SSO) Direct Login URL Generator using UserHelper |
| 2 | + |
| 3 | +1. [Introduction](#introduction) |
| 4 | +2. [Installation](#installation) |
| 5 | +3. [Example & Usage](#usage) |
| 6 | +4. [Security](#security) |
| 7 | + |
| 8 | +## Introduction<a name="introduction"></a> |
| 9 | + |
| 10 | +The UserHelper script include provides functions for generating direct login URLs for users in ServiceNow. This functionality is similar to the impersonate user feature in ServiceNow, but it allows you to directly log in the user without requiring them to enter any credentials. |
| 11 | + |
| 12 | +## Installation<a name="installation"></a> |
| 13 | + |
| 14 | +This script include required Digest Token Authentication Integration below: |
| 15 | + |
| 16 | +#### Prerequisites |
| 17 | + |
| 18 | +* Multi-Provider SSO plugin is activated [documentation](https://docs.servicenow.com/bundle/vancouver-platform-security/page/integrate/single-sign-on/task/t_ActivateMultipleProviderSSO.html) |
| 19 | +* Multi-Provider SSO properties are configured [documentation](https://docs.servicenow.com/bundle/vancouver-platform-security/page/integrate/single-sign-on/task/t_ConfigureMultiProviderSSOProps.html) |
| 20 | + |
| 21 | +#### Steps |
| 22 | + |
| 23 | +1. Go to **Multi-Provider SSO** > **Identity Providers**. |
| 24 | +2. Select the **Digested Token** record. |
| 25 | +3. Add a **Secret Passphrase**. This will be the `<YOUR_SECRET_KEY>` in the script include. |
| 26 | +4. Note the **sys_id** of the **Digested Token** record. This will be the `<SSO_PROVIDER_SYS_ID>` for the script include. |
| 27 | + |
| 28 | +## Usage<a name="usage"></a> |
| 29 | + |
| 30 | +To generate a direct login URL for a user, you can use the `login()` function provided by the UserHelper script include. This function takes the user's name or GlideRecord as input and returns a URL that the user can use to log in directly. |
| 31 | + |
| 32 | +The following example shows how to use the UserHelper script include to generate a direct login URL for a user: |
| 33 | +```javascript |
| 34 | +// Generate a direct login URL for the user "admin". |
| 35 | +var userHelper = new UserHelper(); |
| 36 | + |
| 37 | +// Generate a direct login URL for the user "admin". |
| 38 | +var loginUrl = userHelper.login('admin'); |
| 39 | +``` |
| 40 | +```javascript |
| 41 | +// Generate a direct login URL for the user with the sys_id "1234567890", email. |
| 42 | +var userHelper = new UserHelper(); |
| 43 | +userHelper.getUserById('1234567890'); //userHelper.getUserByEmail('<EMAIL>'); |
| 44 | + |
| 45 | +// Generate a direct login URL for the user "admin". |
| 46 | +var loginUrl = userHelper.login(); |
| 47 | + |
| 48 | +//loginUrl: https://<instance>.service-now.com/?glide_sso_id=<SSO_PROVIDER_SYS_ID>&SM_USER=admin&DE_USER=htrULTFZTOLl9PHEvNBejz65ghxp6dJgDazXXv9v/wY= |
| 49 | +``` |
| 50 | + |
| 51 | +## Security<a name="security"></a> |
| 52 | +It is crucial to emphasize that the UserHelper script include provides direct access to users without requiring any credentials. Therefore, it is important to set proper security policies to secure this script include. Make sure to follow best practices for securing access to this functionality. |
0 commit comments