Skip to content

Instantly share code, notes, and snippets.

@Tanver-Hasan
Last active December 17, 2020 15:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tanver-Hasan/640ab259a333151df35c8efe9cbc839f to your computer and use it in GitHub Desktop.
Save Tanver-Hasan/640ab259a333151df35c8efe9cbc839f to your computer and use it in GitHub Desktop.
Obtain Azure AD access token and refresh token when using Auth0 as service provider and Azure AD as an Identity Provider

There is no standard way to renew identity provider access tokens through Auth0. The mechanism for renewing identity provider access tokens varies for each provider. In the case of Azure AD, you can request refresh token to renew the access token once it expires. Auth0 dashboard does not allow you to include refresh token scope when autneticating with Azure AD. However, one can set scope manually via Management API and request additional scope.

@Tanver-Hasan
Copy link
Author

Tanver-Hasan commented Dec 17, 2020

Example Curl command: copy the options object from the first API call and include upstream_params

curl  --request PATCH 'https://[Auth0 Domain]/api/v2/connections/[Connection ID]' \
--header 'Authorization: Bearer [Auth0 Management API]' \
--header 'Content-Type: application/json' \
--data '{
    "options": {
       // other params as copied
        "upstream_params": {
            "scope": {
                "value": "openid profile email offline_access User.Read"
            }
        }
    }
}'

Once the user finishes the Authentication with Azure AD, the user should have access_token and refresh token in the identities object.

To obtain Azure AD access token and refresh token, you should call /api/v2/users/{id} endpoint which returns identities object

Then, you can use azure ad access token to call graph API.

@Tanver-Hasan
Copy link
Author

@Tanver-Hasan
Copy link
Author

Remember to Allow Graph API permission in Azure Portal

Screenshot 2020-12-17 at 13 25 52

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment