REST API scope troubleshooting
Summarize
Summarized using AI
This content was generated using new OpenAI-powered functionality. Results are provided on an as is basis and are not guaranteed to be accurate or complete.
Summary of REST API scope troubleshooting
This guide addresses common issues encountered when configuring or using REST API scopes in ServiceNow, particularly focusing on authentication scopes and access token behaviors. It helps customers understand how to resolve problems related to authorization scope checks during REST API calls.
Show less
Troubleshooting Actions
- No auth scope check at runtime despite linking REST API to auth scope: Ensure the
sysapiaccesspolicyrecord is active and the system propertycom.glide.rest.api.auth.scope.check.enableis not set to false. Verify the OAuth token includes the appropriate useraccount auth scope. - Access token with different auth scope still accesses REST API: Confirm the relevant record is active. Check for other overlapping records with different apply methods, versions, or resources that might grant access.
- Auth scope not applied for BasicAuth or mutualAuth: This is expected since auth scope checks apply only to OAuth access tokens or OIDC tokens, not to BasicAuth, session cookies, or certificate-based authentication.
- 403 error with OAuth access token: Look for the error message "Missing required api access scope" indicating a failed auth scope check.
- Pre-defined useraccount deleted: Restore by exporting the useraccount XML from another instance or create a new useraccount and update the system property
glide.oauth.token.scope.useraccountto the newsysid.
Frequently Asked Questions
- Can one OAuth token have multiple auth scopes? Yes, each OAuth token inherits all auth scopes linked to its oauthentity.
- Can different tokens with different auth scopes access the same REST API? Yes, if any auth scope matches, access is granted.
- Does useraccount auth scope grant full REST API access? Yes, tokens with useraccount auth scope have full access.
- Can OAuth token scopes be changed dynamically? Yes, auth scopes are retrieved from the linked oauthentity during runtime, not hard-coded in the token.
- Do auth scopes remain after token refresh? Yes, unless modified by an admin on the oauthentity.
- Can a new useraccount auth scope be created if the original is deleted? Creating a new auth scope with the same name does not work because runtime checks by sysid. Instead, update the system property
glide.oauth.token.scope.useraccountwith the new sysid. - Does changing auth scopes linked to an oauthentity affect existing tokens? Yes, all tokens issued by that entity reflect the updated scopes at runtime.
- Can tokens from the same oauthentity have different auth scopes? No, all tokens from the same oauthentity share the same auth scopes.
- Can different auth scopes be assigned to the same REST API endpoint? No, each REST API endpoint has a unique constraint for auth scopes, but multiple matching auth scopes can exist for the same API.
- Is auth scope check applied for BasicAuth? No, it only applies to OAuth and OIDC tokens.
Troubleshooting actions can help resolve common issues when setting up or running the REST API scope.
| Issue | Action |
|---|---|
| REST API is linked with auth scope, however in runtime there is no auth scope check even using Bearer token authentication. |
|
| REST API is linked with auth_scope1, however the access token which has auth_scope2 is also able to access it. |
|
| REST API is linked with auth scope, however in runtime there is no auth scope check for basicAuth and mutualAuth. | It is expected since the REST API auth scope only applies to the OAuth access token or OIDC token. It doesn’t apply BasicAuth, Session Cookie and Certificate based authentication. |
| REST API call return 403 when using the OAuth access token. | Check for the error message "Missing required api access scope". If found then the auth scope check fails for this REST API |
Pre-defined useraccount is deleted and not sure to
restore. |
Export useraccount as xml from the other
instance and import it or create an useraccount and modify system
property glide.oauth.token.scope.useraccount to the newly created
sys_id record. |
Frequently asked questions
Following are some of the frequently asked question when using the REST API Auth scope:
- Can one OAuth token be linked with several auth scopes?
- Yes, one
oauth_entitycan be linked with multiple auth scopes, every OAuth token issued by thisoauth_entityhas the same auth scopes. - Can different OAuth tokens with different auth scopes access the same REST API?
- Yes, for the same REST API, it may be accessed by different auth scopes. As long as one auth scope is matched, the auth scope returns the results.
- Can OAuth access token with
useraccountauth scope access any REST APIs? - Yes, the
useraccounthas full access to auth scope. - Can OAuth access token OAuth scope be changed dynamically?
- Yes, the auth scoped is not hard-coded with the access token in the
oauth_credentialtable. Instead auth scope is getting from linkedoauth_entityduring runtime. - Can OAuth token keep same auth scopes after refresh?
- Yes, auth scope will not change after token refresh, unless
oauth_adminmodify auth scope linked withoauth_entity. - Pre-defined
useraccountauth scope record is deleted, can a new auth scope with nameuseraccountbe created? - Creating a new auth scope with the same
useraccountdoesn't work. In the runtime, it uses thesys_idinstead of name to do the auth scope check, modify the system property glide.oauth.token.scope.useraccount to the newly createdsys_idrecord. - If admin modify auth scoped linked with
oauth_entity, are all the existing OAuth access token issued by this OAuth entity changed also? - Yes, the auth scope is not directly linked with the OAuth access token, it is getting from
oauth_entityduring runtime. - Can different OAuth access tokens issued by the same
oauth_entityhave different auth scopes? - No, all access to the token is issued by the same
oauth_entityand always have the same auth scopes. - Can a user define different auth scopes for a particular endpoint?
- No, there is a unique constrain check for a particular REST API endpoint. However for the same REST API endpoint, it may have more than one matched auth scopes.
- Is the auth scope check used for BasicAuth also?
- No, auth scope check is only OAuth access token and OIDC token, it is not applied for basicAuth and mutualAuth