This article provides guidance on how an app can access Microsoft Graph on behalf of a user, also called delegated access.
In this article, you complete the following steps in using the OAuth 2.0 authorization code grant flow.
- Request authorization.
- Request an access token.
- Use the access token to call Microsoft Graph.
- [Optional] Use the refresh token to renew an expired access token.
Prerequisites
Before proceeding with the steps in this article.
- Understand the authentication and authorization concepts in the Microsoft identity platform.
- Register the app with Microsoft Entra ID. Register an application with the Microsoft identity platform. Save the following values from the app registration.
- The application ID (referred to as Object ID on the Microsoft Entra admin center).
- A client secret (application password), a certificate, or a federated identity credential. This property isn't needed for public clients like native, mobile, and single-page applications.
- A redirect URI for the app to receive token responses from Microsoft Entra ID.
Step 1. Request Authorization.
In the request URL, you call the /authorize endpoint and specify the required and recommended properties as query parameters.
In the following example, the app requests the User. Read and Mail. Read Microsoft Graph permissions, which allow the app to read the profile and mail of the signed-in user, respectively. The offline_access permission is a standard OIDC scope that's requested so that the app can get a refresh token. The app can use the refresh token to get a new access token when the current one expires.
- Base URL: https://login.microsoftonline.com/{tenantID}/oauth2/v2.0/authorize?client_id=<clientId>&response_type=code&redirect_uri=<redirectUri>&response_mode=query&scope=offline_access%20user.read%20mail.read&state=12345
- Method: GET
- Replace Parameters ClientID as per the app you created.
- Replace {tenantID}: The {tenantID} value in the path of the request can be used to control who can sign into the application. In our case, we can get it from the Azure app.
The allowed values are.
- Common for both Microsoft accounts and work or school accounts
- organizations for work or school accounts only
- consumers for Microsoft accounts only
- tenant identifiers such as the tenant ID or domain name.
Step 2. After the app sends the authorization request, the user is asked to enter their credentials to authenticate with Microsoft.
The Microsoft identity platform v2.0 endpoint ensures that the user has consented to the permissions indicated in the scope query parameter. If there's any permission that the user or administrator hasn't consented to, they're asked to consent to the required permissions.


Join the conversation! Your thoughts help the community grow.