You can configure personal OAuth authentication with the REST step in Flow Designer.
About this task
This task guides you through configuring personal OAuth authentication for REST steps in ServiceNow® Flow Designer. It enables REST calls to run using the session user's credentials, ensuring secure and personalized API access.
For information on how to check if a personal OAuth token exists for a user, see Get Personal OAuth Token (using GlideOAuthClient).
For information to generate the initial token for a user, who doesn’t have access to the credentials page, see Generate Personal Auth Initiator URL.
Procedure
-
Navigate to Application Registries, and create an OAuth application registry to connect to an external endpoint.
-
Navigate to Connection & Credentials Aliases, and create a connection alias.
-
Navigate to HTTP(s) Connection, and update the external end-point details for the connection record created in the previous step.
-
Create an OAuth Credential.
-
Navigate to OAuth 2.0 Credentials.
-
Create a new OAuth credential record and link it to the OAuth profile created in Step 1.
-
Add the IntegrationType field to the credential form.
-
Update the IntegrationType field of the credential created in Step 4 to Personal.
-
Generate a personal access token.
-
As a logged-in user, open the credential record.
-
Select Get OAuth Token to create a personal token.
-
Select Manage Tokens to view and manage the tokens.
Note: Add a UI action to your application so that the end users can generate tokens. Only administrators can open the credential form directly.
-
Navigate to Action to create an action for your use case.
-
Add a REST step to the action.
Select the connection alias created in Step 2.
Note: Test the action with the REST outbound call. The credential is marked to be used for personal integration. The REST step might display an error since the action runs
with the System integration role.
-
Create a new subflow, and add the action created in Step 8.
-
In the Subflow properties window, select User who initiates session in the Run As text field.
Don’t select System User instead from the Run As text field.
-
Test the subflow.
The REST step uses the token created for the session user. The subflow can also be invoked using FlowAPIs.
- Sample script to invoke a subflow:
-
try {
// Execute synchronously in the foreground. Allows access to subflow outputs.
var result = sn_fd.FlowAPI.getRunner()
.subflow('global.getpersonalincidentssubflow')
.inForeground()
.run();
var outputs = result.getOutputs();
} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}
-
Manage missing or expired tokens.
If the session user has no access token, the REST request returns a HTTP 401 Unauthorized status code response. Ensure that the token is created before you initiate the flow.
If the access token is expired but a valid refresh token exists, the system automatically renews the access token.