You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/active-directory-b2c/authorization-code-flow.md
+15-14Lines changed: 15 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,11 @@
1
1
---
2
2
title: Authorization code flow - Azure Active Directory B2C
3
-
description: Learn how to build web apps by using Azure AD B2C and OpenID Connect authentication protocol.
3
+
description: Learn how to implement OAuth 2.0 authorization code flow in Azure AD B2C for web, mobile, and desktop apps, including setup and HTTP request examples.
4
4
author: kengaderdus
5
5
manager: CelesteDG
6
6
ms.service: azure-active-directory
7
7
ms.topic: concept-article
8
-
ms.date: 01/11/2024
8
+
ms.date: 02/17/2025
9
9
ms.author: kengaderdus
10
10
ms.subservice: b2c
11
11
ms.custom: fasttrack-edit
@@ -21,7 +21,7 @@ You can use the OAuth 2.0 authorization code grant in apps installed on a device
21
21
22
22
The OAuth 2.0 authorization code flow is described in [section 4.1 of the OAuth 2.0 specification](https://tools.ietf.org/html/rfc6749). You can use it for authentication and authorization in most [application types](application-types.md), including web applications, single-page applications, and natively installed applications. You can use the OAuth 2.0 authorization code flow to securely acquire access tokens and refresh tokens for your applications, which can be used to access resources that are secured by an [authorization server](protocols-overview.md). The refresh token allows the client to acquire new access (and refresh) tokens once the access token expires, typically after one hour.
23
23
24
-
This article focuses on the **public clients** OAuth 2.0 authorization code flow. A public client is any client application that cannot be trusted to securely maintain the integrity of a secret password. This includes single-page applications, mobile apps, desktop applications, and essentially any application that doesn't run on a server.
24
+
This article focuses on the **public clients** OAuth 2.0 authorization code flow. A public client is any client application that can't be trusted to securely maintain the integrity of a secret password. This includes single-page applications, mobile apps, desktop applications, and essentially any application that doesn't run on a server.
25
25
26
26
> [!NOTE]
27
27
> To add identity management to a web app by using Azure AD B2C, use [OpenID Connect](openid-connect.md) instead of OAuth 2.0.
| client_id |Required |The application ID assigned to your app in the [Azure portal](https://portal.azure.com). |
64
64
| response_type |Required |The response type, which must include `code` for the authorization code flow. You can receive an ID token if you include it in the response type, such as `code+id_token`, and in this case, the scope needs to include `openid`.|
65
65
| redirect_uri |Required |The redirect URI of your app, where authentication responses are sent and received by your app. It must exactly match one of the redirect URIs that you registered in the portal, except that it must be URL-encoded. |
66
-
| scope |Required |A space-separated list of scopes. The `openid` scope indicates a permission to sign in the user and get data about the user in the form of ID tokens. The `offline_access` scope is optional for web applications. It indicates that your application will need a *refresh token* for extended access to resources. The client-id indicates the token issued are intended for use by Azure AD B2C registered client. The `https://{tenant-name}/{app-id-uri}/{scope}` indicates a permission to protected resources, such as a web API. For more information, see [Request an access token](access-tokens.md#scopes). |
66
+
| scope |Required |A space-separated list of scopes. The `openid` scope indicates a permission to sign in the user and get data about the user in the form of ID tokens. The `offline_access` scope is optional for web applications. It indicates that your application needs a *refresh token* for extended access to resources. The client-id indicates the token issued are intended for use by Azure AD B2C registered client. The `https://{tenant-name}/{app-id-uri}/{scope}` indicates a permission to protected resources, such as a web API. For more information, see [Request an access token](access-tokens.md#scopes). |
67
67
| response_mode |Recommended |The method that you use to send the resulting authorization code back to your app. It can be `query`, `form_post`, or `fragment`. |
68
68
| state |Recommended |A value included in the request that can be a string of any content that you want to use. Usually, a randomly generated unique value is used, to prevent cross-site request forgery attacks. The state also is used to encode information about the user's state in the app before the authentication request occurred. For example, the page the user was on, or the user flow that was being executed. |
69
-
| prompt |Optional |The type of user interaction that is required. Currently, the only valid value is `login`, which forces the user to enter their credentials on that request. Single sign-on will not take effect. |
69
+
| prompt |Optional |The type of user interaction that is required. Currently, the only valid value is `login`, which forces the user to enter their credentials on that request. Single sign-on won't take effect. |
70
70
| code_challenge | recommended / required | Used to secure authorization code grants via Proof Key for Code Exchange (PKCE). Required if `code_challenge_method` is included. You need to add logic in your application to generate the `code_verifier` and `code_challenge`. The `code_challenge` is a Base64 URL-encoded SHA256 hash of the `code_verifier`. You store the `code_verifier` in your application for later use, and send the `code_challenge` along with the authorization request. For more information, see the [PKCE RFC](https://tools.ietf.org/html/rfc7636). This is now recommended for all application types - native apps, SPAs, and confidential clients like web apps. |
71
-
|`code_challenge_method`| recommended / required | The method used to encode the `code_verifier` for the `code_challenge` parameter. This *SHOULD* be `S256`, but the spec allows the use of `plain` if for some reason the client cannot support SHA256. <br/><br/>If you exclude the `code_challenge_method`, but still include the `code_challenge`, then the `code_challenge` is assumed to be plaintext. Microsoft identity platform supports both `plain` and `S256`. For more information, see the [PKCE RFC](https://tools.ietf.org/html/rfc7636). This is required for [single page apps using the authorization code flow](tutorial-register-spa.md).|
72
-
| login_hint | No| Can be used to pre-fill the sign-in name field of the sign-in page. For more information, see [Prepopulate the sign-in name](direct-signin.md#prepopulate-the-sign-in-name). |
71
+
|`code_challenge_method`| recommended / required | The method used to encode the `code_verifier` for the `code_challenge` parameter. This *SHOULD* be `S256`, but the spec allows the use of `plain` if for some reason the client can't support SHA256. <br/><br/>If you exclude the `code_challenge_method`, but still include the `code_challenge`, then the `code_challenge` is assumed to be plaintext. Microsoft identity platform supports both `plain` and `S256`. For more information, see the [PKCE RFC](https://tools.ietf.org/html/rfc7636). This is required for [single page apps using the authorization code flow](tutorial-register-spa.md).|
72
+
| login_hint | No| Can be used to prefill the sign-in name field of the sign-in page. For more information, see [Prepopulate the sign-in name](direct-signin.md#prepopulate-the-sign-in-name). |
73
73
| domain_hint | No| Provides a hint to Azure AD B2C about the social identity provider that should be used for sign-in. If a valid value is included, the user goes directly to the identity provider sign-in page. For more information, see [Redirect sign-in to a social provider](direct-signin.md#redirect-sign-in-to-a-social-provider). |
74
74
| Custom parameters | No| Custom parameters that can be used with [custom policies](custom-policy-overview.md). For example, [dynamic custom page content URI](customize-ui-with-html.md?pivots=b2c-custom-policy#configure-dynamic-custom-page-content-uri), or [key-value claim resolvers](claim-resolver-overview.md#oauth2-key-value-parameters). |
75
75
@@ -87,7 +87,7 @@ code=AwABAAAAvPM1KaPlrEqdFSBzjqfTGBCmLdgfSTLEMPGYuNHSUYBrq... // the auth
87
87
88
88
| Parameter | Description |
89
89
| --- | --- |
90
-
| code |The authorization code that the app requested. The app can use the authorization code to request an access token for a target resource. Authorization codes are very short-lived. Typically, they expire after about 10 minutes. |
90
+
| code |The authorization code that the app requested. The app can use the authorization code to request an access token for a target resource. Authorization codes are short-lived. Typically, they expire after about 10 minutes. |
91
91
| state |See the full description in the table in the preceding section. If a `state` parameter is included in the request, the same value should appear in the response. The app should verify that the `state` values in the request and response are identical. |
92
92
93
93
Error responses also can be sent to the redirect URI so that the app can handle them appropriately:
@@ -126,9 +126,9 @@ grant_type=authorization_code
126
126
| Parameter | Required? | Description |
127
127
| --- | --- | --- |
128
128
|{tenant}| Required | Name of your Azure AD B2C tenant|
129
-
|{policy}| Required| The user flow that was used to acquire the authorization code. You cannot use a different user flow in this request. |
129
+
|{policy}| Required| The user flow that was used to acquire the authorization code. You can't use a different user flow in this request. |
130
130
| client_id |Required |The application ID assigned to your app in the [Azure portal](https://portal.azure.com).|
131
-
| client_secret | Yes, in Web Apps | The application secret that was generated in the [Azure portal](https://portal.azure.com/). Client secrets are used in this flow for Web App scenarios, where the client can securely store a client secret. For Native App (public client) scenarios, client secrets cannot be securely stored, and therefore are not used in this call. If you use a client secret, please change it on a periodic basis. |
131
+
| client_secret | Yes, in Web Apps | The application secret that was generated in the [Azure portal](https://portal.azure.com/). Client secrets are used in this flow for Web App scenarios, where the client can securely store a client secret. For Native App (public client) scenarios, client secrets can't be securely stored, and therefore aren't used in this call. If you use a client secret, change it on a periodic basis. |
132
132
| grant_type |Required |The type of grant. For the authorization code flow, the grant type must be `authorization_code`. |
133
133
| scope |Recommended |A space-separated list of scopes. A single scope value indicates to Azure AD B2C both of the permissions that are being requested. Using the client ID as the scope indicates that your app needs an access token that can be used against your own service or web API, represented by the same client ID. The `offline_access` scope indicates that your app needs a refresh token for long-lived access to resources. You also can use the `openid` scope to request an ID token from Azure AD B2C. |
134
134
| code |Required |The authorization code that you acquired in from the `/authorize` endpoint. |
Access tokens and ID tokens are short-lived. After they expire, you must refresh them to continue to access resources. When you refresh the access token, Azure AD B2C returns a new token. The refreshed access token will have updated `nbf` (not before), `iat` (issued at), and `exp` (expiration) claim values. All other claim values will be the same as the originally issued access token.
187
+
Access tokens and ID tokens are short-lived. After they expire, you must refresh them to continue to access resources. When you refresh the access token, Azure AD B2C returns a new token. The refreshed access token will have updated `nbf` (not before), `iat` (issued at), and `exp` (expiration) claim values. All other claim values are the same as the originally issued access token.
188
188
189
189
190
190
To refresh the token, submit another POST request to the `/token` endpoint. This time, provide the `refresh_token` instead of the `code`:
@@ -204,11 +204,11 @@ grant_type=refresh_token
204
204
| Parameter | Required? | Description |
205
205
| --- | --- | --- |
206
206
|{tenant}| Required | Name of your Azure AD B2C tenant|
207
-
|{policy} |Required |The user flow that was used to acquire the original refresh token. You cannot use a different user flow in this request. |
207
+
|{policy} |Required |The user flow that was used to acquire the original refresh token. You can't use a different user flow in this request. |
208
208
| client_id |Required |The application ID assigned to your app in the [Azure portal](https://portal.azure.com). |
209
-
| client_secret | Yes, in Web Apps | The application secret that was generated in the [Azure portal](https://portal.azure.com/). Client secrets are used in this flow for Web App scenarios, where the client can securely store a client secret. For Native App (public client) scenarios, client secrets cannot be securely stored, and therefore are not used in this call. If you use a client secret, please change it on a periodic basis. |
209
+
| client_secret | Yes, in Web Apps | The application secret that was generated in the [Azure portal](https://portal.azure.com/). Client secrets are used in this flow for Web App scenarios, where the client can securely store a client secret. For Native App (public client) scenarios, client secrets can't be securely stored, and therefore aren't used in this call. If you use a client secret, please change it on a periodic basis. |
210
210
| grant_type |Required |The type of grant. For this leg of the authorization code flow, the grant type must be `refresh_token`. |
211
-
| scope |Recommended |A space-separated list of scopes. A single scope value indicates to Microsoft Entra ID both of the permissions that are being requested. Using the client ID as the scope indicates that your app needs an access token that can be used against your own service or web API, represented by the same client ID. The `offline_access` scope indicates that your app will need a refresh token for long-lived access to resources. You also can use the `openid` scope to request an ID token from Azure AD B2C. |
211
+
| scope |Recommended |A space-separated list of scopes. A single scope value indicates to Microsoft Entra ID both of the permissions that are being requested. Using the client ID as the scope indicates that your app needs an access token that can be used against your own service or web API, represented by the same client ID. The `offline_access` scope indicates that your app needs a refresh token for long-lived access to resources. You also can use the `openid` scope to request an ID token from Azure AD B2C. |
212
212
| redirect_uri |Optional |The redirect URI of the application where you received the authorization code. |
213
213
| refresh_token |Required |The original refresh token that you acquired in the second leg of the flow. |
214
214
@@ -248,6 +248,7 @@ Error responses look like this:
248
248
| error_description |A specific error message that can help you identify the root cause of an authentication error. |
249
249
250
250
## Use your own Azure AD B2C directory
251
+
251
252
To try these requests yourself, complete the following steps. Replace the example values we used in this article with your own values.
252
253
253
254
1.[Create an Azure AD B2C directory](tutorial-create-tenant.md). Use the name of your directory in the requests.
Copy file name to clipboardExpand all lines: articles/active-directory-b2c/configure-authentication-in-azure-static-app.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,13 @@
1
1
---
2
-
title: Configure authentication in an Azure Static Web App by using Azure Active Directory B2C
2
+
title: Configure authentication in an Azure Static Web App by using Azure AD B2C
3
3
description: This article discusses how to use Azure Active Directory B2C to sign in and sign up users in an Azure Static Web App.
4
4
5
5
author: kengaderdus
6
6
manager: CelesteDG
7
7
ms.service: azure-active-directory
8
8
9
9
ms.topic: reference
10
-
ms.date: 01/11/2024
10
+
ms.date: 02/17/2025
11
11
ms.author: kengaderdus
12
12
ms.subservice: b2c
13
13
ms.custom: "b2c-support"
@@ -129,8 +129,8 @@ Once you've added the app ID and secret, use the following steps to add the Azur
129
129
## Step 4: Check the Azure Static Web APP
130
130
131
131
1. Navigate to `/.auth/login/aadb2c`. The `/.auth/login` points the Azure Static app login endpoint. The `aadb2c` references to your [OpenID Connect identity provider](#31-add-an-openid-connect-identity-provider). The following URL demonstrates an Azure Static app login endpoint: `https://witty-island-11111111.azurestaticapps.net/.auth/login/aadb2c`.
132
-
1. Complete the signup or signin process.
133
-
1. In your browser debugger, [run the following JavaScript in the Console](/microsoft-edge/devtools-guide-chromium/console/console-javascript). The JavaScript code will present information about the sign in user.
132
+
1. Complete the sign-up or sign-in process.
133
+
1. In your browser debugger, [run the following JavaScript in the Console](/microsoft-edge/devtools-guide-chromium/console/console-javascript). The JavaScript code presents information about the sign in user.
Copy file name to clipboardExpand all lines: articles/active-directory-b2c/configure-tokens.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ author: kengaderdus
5
5
manager: CelesteDG
6
6
ms.service: azure-active-directory
7
7
ms.topic: how-to
8
-
ms.date: 01/11/2024
8
+
ms.date: 02/17/2025
9
9
ms.author: kengaderdus
10
10
ms.subservice: b2c
11
11
zone_pivot_groups: b2c-policy-type
@@ -233,7 +233,7 @@ The OutputClaim element contains the following attributes:
233
233
234
234
When using the [OAuth 2.0 authorization code flow](authorization-code-flow.md), the app can use the authorization code to request an access token for a target resource. Authorization codes are short-lived that expire after about 10 minutes. The authorization code lifetime can't be configured. Make sure your application redeems the authorization codes within 10 minutes.
235
235
236
-
## Next steps
236
+
## Related content
237
237
238
238
- Learn more about how to [request access tokens](access-tokens.md).
239
239
- Learn how to build [Resilience through developer best practices](../active-directory/architecture/resilience-b2c-developer-best-practices.md?bc=/azure/active-directory-b2c/bread/toc.json&toc=/azure/active-directory-b2c/TOC.json).
0 commit comments