1. Authorization Code Grant Flow

Overview

According to the OAuth authorization code grant flow, an authorization server sends a temporary (authorization) code to a client. The code is exchanged for a token. This flow is available for confidential clients, for example, web applications with a backend that can store credentials securely. This way, the client can obtain one or more of the following token types:

OAuth Code Flow

Steps

  1. A user tries to access the application (the client).
  2. The client calls the authorization server's authorize endpoint.
  3. curl --location \
    --get \
    --url "https://$TENANT_ID.$REGION_ID.authz.cloudentity.io/$TENANT_ID/$WORKSPACE_ID/oauth2/authorize" \
    --data-urlencode "response_type=code" \
    --data-urlencode "client_id=$CLIENT_ID"
                
  4. The authorization server responds with the redirect URI. The user gets redirected to the login & content form (if any).
  5. The user authenticates with his credentials and gives his consent.
  6. The authorization server issues an authorization code.
  7. The client application requests authentication to the token endpoint using the authentication method configured and the authorization code provided in the previous step.

    The grant_type value in the API call must be authorization_code.

  8. curl --request POST \
    --url "https://$TENANT_ID.$REGION_ID.authz.cloudentity.io/$TENANT_ID/$WORKSPACE_ID/oauth/token" \
    --data-raw "grant_type=authorization_code&code=$CODE&client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET"
                
  9. The authorization server validates the authorization code.
  10. The authorization server returns the token.
  11. The client application requests protected resources (API / Azure Resources) from the resource server and submits the token it received in the previous step.
  12. The resource server validates the token and responds with the requested resources.

Use Case

Security