Share via

AuthorizationCodeCredential provider for graph sdk

Anonymous
2021-12-09T14:00:09.25+00:00

I am trying to use the AuthorizationCodeCredential from https://learn.microsoft.com/en-us/graph/sdks/choose-authentication-providers?tabs=Java#authorization-code-provider.

Where does the authorization code value come in from? Does the use have to interactively via a webpage invoke the /authorize endpoint, we have to cache the code value and then build out this provider?

Once its built out, do we get the access and refresh tokens for free? Do we then need to do anything to keep them alive?

Microsoft Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Microsoft Graph

1 answer

Sort by: Most helpful
  1. Shweta Mathur 30,456 Reputation points Microsoft Employee Moderator
    2021-12-10T10:26:02.137+00:00

    Hi @Anonymous

    Azure AD authorization code flow requires user interaction to authenticate the user and get Authorization code using /authorize endpoint.
    AuthorizationCodeCredential require prefetched authorization code which you can get from the query parameter in redirect URL specified while calling /authorize endpoint.

    You can extract that query parameter and pass in AuthorizationCodeCredential to get the access and refresh token.

    Authorization Code is a temporary code that is valid for a very short time and is intended only for receiving an AccessToken and RefreshToken. There is no need to store it. If you need to get new access token after access token expire, you don’t need code . You can use refresh token this time to get active access token.

    Refer https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow for authorize endpoint and code and tokens formats.

    Hope this helps.

    Thanks,
    Shweta

    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.