get ID token

Agrawal, Amit [JOICA] 0 Reputation points
2026-01-05T17:44:42.91+00:00

What are the API calls required to get the id and refresh token

Azure App Configuration
Azure App Configuration

An Azure service that provides hosted, universal storage for Azure app configurations.


2 answers

Sort by: Most helpful
  1. Rakesh Mishra 11,340 Reputation points Microsoft External Staff Moderator
    2026-01-05T18:08:48.13+00:00

    Hi @Agrawal, Amit [JOICA], Welcome to the Microsoft Q&A Platform! Thank you for asking your question here.

    It seems like you're looking to figure out the API calls needed to obtain an ID token and a refresh token. This usually involves interacting with Microsoft Entra ID (formerly known as Azure AD), and there are a few common approaches depending on your application's architecture.

    Here’s a general outline of how you would go about this:
    1. Use the Microsoft Authentication Library (MSAL):
      • The MSAL library is designed for acquiring tokens from Microsoft Entra ID easily. You'll typically want to choose an authentication flow that fits your application type (web app, mobile app, etc.).
      • For example, the OAuth 2.0 authorization code flow is a common method used in web applications. It allows the application to get an access token and ID token after user authentication.
    2. Sample API Call Flow:
      • Redirect your user to the Microsoft Entra authorization endpoint:
             
             GET https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize
             
        
      • After the user signs in, they will be redirected back to your specified redirect URI with an authorization code.
      • Exchange the authorization code for tokens using the token endpoint:
             
             POST https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token
             
             Content-Type: application/x-www-form-urlencoded
             
             grant_type=authorization_code
             
             &client_id={your-client-id}
             
             &client_secret={your-client-secret}
             
             &redirect_uri={your-redirect-uri}
             
             &code={authorization-code}
             
        
    3. Token Scope:
      • Ensure you specify the appropriate scopes when doing the initial authorization request, which might include both access and ID token scopes (e.g., openid, profile, offline_access for a refresh token).
    4. Refresh Token:
      • To obtain a new access token using the refresh token, make a similar POST request to the token endpoint, but specify grant_type=refresh_token and include the refresh token in your request.
    Example of Refresh Token API Call:
    
    POST https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token
    
    Content-Type: application/x-www-form-urlencoded
    
    grant_type=refresh_token
    
    &client_id={your-client-id}
    
    &client_secret={your-client-secret}
    
    &refresh_token={your-refresh-token}
    
    
    Important Notes:
    • Always ensure that your application has appropriate permissions assigned in the Azure portal for accessing the necessary token scopes.
    • The endpoints and flow may change slightly based on whether you’re using Azure AD or Azure AD B2C, so make sure to use the right documentation relevant to your implementation.
    References:

    Hope this helps you get started! If you have any further questions or need clarification on a specific part, feel free to ask!

    Was this answer helpful?


  2. AI answer

    2026-01-05T17:44:51.21+00:00

    To obtain an ID token and a refresh token, you typically follow the OAuth 2.0 authorization code flow. Here are the API calls required:

    1. Authorization Request: Redirect the user to the authorization endpoint to obtain an authorization code. The request will look like this:
         GET https://login.microsoftonline.com/<TenantID>/oauth2/v2.0/authorize?
         client_id=<ClientID>&
         response_type=code&
         redirect_uri=<RedirectURI>&
         scope=openid offline_access
      
      • Replace <TenantID>, <ClientID>, and <RedirectURI> with your specific values.
      • The scope parameter must include openid to request an ID token and offline_access to receive a refresh token.
    2. Token Request: After the user consents, you will receive an authorization code. Use this code to request tokens:
         POST https://login.microsoftonline.com/<TenantID>/oauth2/v2.0/token
         Content-Type: application/x-www-form-urlencoded
         
         client_id=<ClientID>
         &client_secret=<ClientSecret>
         &grant_type=authorization_code
         &code=<authorization_code>
         &redirect_uri=<RedirectURI>
         &scope=openid offline_access
      
      • Replace <authorization_code> with the code received in the previous step.
      • The response will include the id_token and a refresh_token if the offline_access scope was requested.
    3. Refreshing the Token: When the access token expires, you can refresh it using the refresh token:
         POST https://login.microsoftonline.com/<TenantID>/oauth2/v2.0/token
         Content-Type: application/x-www-form-urlencoded
         
         client_id=<ClientID>
         &client_secret=<ClientSecret>
         &grant_type=refresh_token
         &refresh_token=<refresh_token>
         &scope=openid offline_access
      
      • This will return a new access token and potentially a new refresh token.

    Make sure to handle the tokens securely and manage their expiration appropriately.

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.