by Tom M.
Introduction
ServiceNow is a cloud platform that manages digital enterprise workflows. The platform provides a lot of tools for custom development in their own application, but it also provides the ability to run external web applications inside their application (in an IFRAME) and interact with the ServiceNow environment through the OpenFrame API. ServiceNow also provides quite a large set of REST API's so external applications can interact with the data.
ServiceNow is an OAuth provider where you can define multiple OAuth clients that are granted access to the environment. Your application can then request an access token with either an "authorization" or "implicit" grant flow.
When retrieving a access token with OAuth the application navigates to the OAuth providers endpoint with some query string parameters. The required query string parameters depend on the grant flow:
Implicit grant
https://{service_now_instance}.service-now.com/oauth_auth.do?response_type=token&redirect_uri={redirect_url}&client_id={client_id}&state={some_app_state_value}
Authorization code
https://{service_now_instance}.service-now.com/oauth_auth.do?response_type=code&redirect_uri={redirect_url}&client_id={client_id}&state={some_app_state_value}
Authorization code with PKCE
https://{service_now_instance}.service-now.com/oauth_auth.do?response_type=code&redirect_uri={redirect_url}&client_id={client_id}&state={some_app_state_value}&code_challenge={some_challenge}&code_challenge_method="S256 or omit the parameter"
When no user is logged on in ServiceNow, a ServiceNow logon screen is shown where the user can enter his credentials. When the provided credentials are valid (or a user is already logged on in ServiceNow), a "grant access" page is shown where the user is notified that the application requests access to ServiceNow. When user presses the "Allow" button, the window redirects to the redirect URL with either the access token in case of an implicit grant flow or an authorization code. An authorization code is short lived and can be used once to request an access and a refresh token.