Skip to main content
It’s recommended to use the OIDC-based Authorization Code Grant if you’re using a web based application with its own back end server for user session management. In the Authorization Code Grant flow, the front end initializes the flow, and leverages back-channel communication between your back end server and Digital Identity Management. This flow is the most secure option because no tokens, or your RP client ID and secret, are exposed to the outside world. Once a user authenticates with their Digital Identity Management ID, Digital Identity Management issues a one-time Authorization Code to the RP. The RP uses the code in a secure back-channel request to obtain the access token, refresh token, or ID token from Digital Identity Management.

Flow Diagram

The diagram below represents the communication between the key actors using the Authorization Code Grant flow: OIDC Authorization Code Flow

Interaction Steps

The interaction steps between each actor in the Authorization Code Grant flow are as a follows:
  1. The user’s browser visits the web application to access the secured service.
  2. Your web app UI checks with its back end to determined whether the user is already considered as signed in. For example, the user’s browser has a cookie or a session ID from a previous login.
  3. Your back end determines that the user is not signed in.
  4. Your back end generates and stores a nonce ASCII string. This is used to validate the OIDC response, and must not be guessable by an outside attacker.
  5. Your back end returns a response to the UI that indicates the browser should redirect to the OIDC Authorization endpoint with parameters appropriate to the application RP.
  6. Your UI generates a secure state ASCII string, and stores it in a browser cookie. This will be used to mitigate against Cross-Site Request Forgery (CSRF/XSRF) attacks.
  7. Your app UI redirects the browser to Digital Identity Management’s /oidc/authorize endpoint with the following HTTP GET query string parameters:
  1. The user’s browser loads the oidc/authorize URL as per the HTTP 302 response from step 7. Digital Identity Management inspects the browser’s cookies to determine if the user is already authenticated. The next step depends on whether the user is already authenticated in Digital Identity Management.
  2. (Conditional) If the request is not valid, or if the user is already authenticated and re-authentication is not being forced, then Digital Identity Management immediately responds with an HTTP 302 Temporary Redirect to the redirect_uri with certain HTTP Query parameters. Skip steps 10 through 12 and go to step 13 directly.
  3. (Conditional) If the user is not authenticated, then Digital Identity Management redirects them to the configured IdP Portal (that is, the central sign-in page for all of your registered RPs).
  4. In the most conventional use case, the user authenticates with Digital Identity Management’s POST /session/start API. This API invokes Digital Identity Management’s multi-step Authenticate User Process. Alternatively, the user may need to first onboard with the Onboard User with Email or Mobile Process, which is invoked by the POST /proces/start/{processName} API. This and other variations are not included in the flow diagram.
  5. Eventually, whether from a /session/start or other Process API call, and potentially after several more steps (for example, to satisfy multi-factor authentication rules, if enabled), the user is authenticated. The final HTTP response from Digital Identity Management includes a special X-Redirect-Location header with a URL constructed from the redirect_uri parameter provided by the RP in step 7. The IdP then redirects the browser to that location.
  6. The user’s browser loads a URL which Digital Identity Management has constructed from the redirect_uri parameter, to which the following HTTP Query parameters will have been added:
  7. Your UI checks the state value in the request against the original state value stored in a browser cookie. If there is a mismatch, a cross-site request forgery (CSRF/XSRF) attack is suspected, and the operation must be aborted with an error.
  8. Your UI passes the received Authorization Code down to your back end.
  9. Your back end makes a call to Digital Identity Management’s POST /oidc/token endpoint with the following parameters to redeem the Authorization Code for actual tokens:
  1. If all parameters are correct and the Authorization Code is valid, Digital Identity Management replies with a JSON payload that contains the requested token(s). The payload is of type application/json, and it consists of a JSON object resembling the following:
    The fields of this JSON object are as follows:
  2. Your back end decodes the ID token, and inspects the payload to make sure the nonce key is present and its value matches the nonce value N from the original request (generated in step 4). If not, a replay attack is suspected and the operation must be aborted with an error.
  3. Your system stores the token(s), preferably on the back end side (for example, in a session state), but also possibly as cookies in the web UI.
  4. Your back end informs the web UI that the user is now considered authenticated or signed in.
  5. As long as the access token remains valid, the user remains authenticated and can take actions. For more details on how to refresh (that is, get replacement) a token, refer to the Refreshing Tokens topic.