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/api-center/includes/api-center-portal-app-registration.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
@@ -35,7 +35,7 @@ If you want to create the app registration manually, follow these steps:
35
35
1. Set **Name** to a meaningful name such as *api-center-portal*
36
36
1. Under **Supported account types**, select **Accounts in this organizational directory (Single tenant)**.
37
37
1. In **Redirect URI**, select **Single-page application (SPA)** and set the URI.
38
-
Enter the URI of your API Center portal deployment, in the following form: `https://<service-name>.portal.<location>.azure-api-center.ms`. Replace `<service name>` and `<location>` with the name of your API center and the location where it's deployed, Example: `https://myapicenter.portal.eastus.azure-api-center.ms`.
38
+
Enter the URI of your API Center portal deployment, in the following form: `https://<service-name>.portal.<location>.azure-apicenter.ms`. Replace `<service name>` and `<location>` with the name of your API center and the location where it's deployed, Example: `https://myapicenter.portal.eastus.azure-apicenter.ms`.
39
39
1. Select **Register**.
40
40
41
41
#### Configure additional redirect URIs for VS Code extension
@@ -49,4 +49,4 @@ When enabling the API Center portal view in the Visual Studio Code extension for
Replace `<application-client-id>` with the application (client) ID of this app. You can find this value on the **Overview** page of the app registration.
52
+
Replace `<application-client-id>` with the application (client) ID of this app. You can find this value on the **Overview** page of the app registration.
Copy file name to clipboardExpand all lines: articles/api-center/set-up-api-center-portal.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
@@ -48,7 +48,7 @@ After you create the API Center portal app registration, you need to configure a
48
48
You can now access the API Center portal:
49
49
* On the **Portal settings** page, select **View API Center portal** to open the portal in a new tab.
50
50
* Or, enter the following URL in your browser, replacing `<service-name>` and `<location>` with the name of your API center and the location where it's deployed:<br/>
Copy file name to clipboardExpand all lines: articles/app-service/configure-authentication-oauth-tokens.md
+47-46Lines changed: 47 additions & 46 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,67 +1,43 @@
1
1
---
2
-
title: Work with OAuth Tokens in AuthN/AuthZ
3
-
description: Learn how to retrieve tokens, refresh tokens, and extend sessions when you use the built-in authentication and authorization in Azure App Service.
2
+
title: Work with OAuth Tokens in Authentication and Authorization
3
+
description: Learn how to retrieve, refresh, and extend session expiration for OAuth tokens when you use Azure App Service built-in authentication and authorization.
4
4
ms.topic: how-to
5
-
ms.date: 03/29/2021
5
+
ms.date: 07/01/2025
6
6
ms.custom: AppServiceIdentity
7
7
author: cephalin
8
8
ms.author: cephalin
9
9
---
10
10
11
-
# Work with OAuth tokens in Azure App Service authentication
11
+
# Manage OAuth tokens in Azure App Service
12
12
13
-
This article shows you how to work with OAuth tokens when you use the built-in [authentication and authorization in Azure App Service](overview-authentication-authorization.md).
13
+
This article shows you how to manage [OAuth](https://www.microsoft.com/security/business/security-101/what-is-oauth) tokens for [built-in authentication and authorization](overview-authentication-authorization.md) in Azure App Service.
14
14
15
15
## Retrieve tokens in app code
16
16
17
-
From your server code, the provider-specific tokens are injected into the request header so that you can easily access them.
17
+
Azure App Service injects your provider-specific tokens into the request header so you can easily access them. To get the provider-specific tokens, [token store](overview-authentication-authorization.md#token-store) must be enabled for the app.
18
18
19
-
The following table lists possible token header names:
19
+
Send an HTTP `GET` request to `/.auth/me` from your client code, such as a mobile app or in-browser JavaScript. The returned JSON has the provider-specific tokens.
20
+
21
+
> [!NOTE]
22
+
> Access tokens are for accessing provider resources, so are present only if you configure your provider with a client secret.
23
+
24
+
The following table lists the OAuth token header names for several App Service built-in providers:
20
25
21
26
| Provider | Header names |
22
27
|-|-|
23
28
| Microsoft Entra |`X-MS-TOKEN-AAD-ID-TOKEN` <br/> `X-MS-TOKEN-AAD-ACCESS-TOKEN` <br/> `X-MS-TOKEN-AAD-EXPIRES-ON` <br/> `X-MS-TOKEN-AAD-REFRESH-TOKEN`|
| Google |`X-MS-TOKEN-GOOGLE-ID-TOKEN` <br/> `X-MS-TOKEN-GOOGLE-ACCESS-TOKEN` <br/> `X-MS-TOKEN-GOOGLE-EXPIRES-ON` <br/> `X-MS-TOKEN-GOOGLE-REFRESH-TOKEN`|
26
31
| X |`X-MS-TOKEN-TWITTER-ACCESS-TOKEN` <br/> `X-MS-TOKEN-TWITTER-ACCESS-TOKEN-SECRET`|
27
32
28
33
> [!NOTE]
29
-
> Different language frameworks might present these headers to the app code in different formats, such as in lowercase or by using title case.
30
-
31
-
From your client code (such as a mobile app or in-browser JavaScript), send an HTTP `GET` request to `/.auth/me` ([token store](overview-authentication-authorization.md#token-store) must be enabled). The returned JSON has the provider-specific tokens.
32
-
33
-
> [!NOTE]
34
-
> Access tokens are for accessing provider resources, so they're present only if you configure your provider with a client secret.
34
+
> Different language frameworks might present these headers to the app code in different formats, such as lowercase or title case.
35
35
36
36
## Refresh auth tokens
37
37
38
-
When your provider's access token (not the [session token](#extend-session-token-expiration-grace-period)) expires, you need to reauthenticate the user before you use that token again. You can avoid token expiration by making a `GET` call to the `/.auth/refresh` endpoint of your application. When called, App Service automatically refreshes the access tokens in the [token store](overview-authentication-authorization.md#token-store) for the authenticated user. Subsequent requests for tokens by your app code get the refreshed tokens. However, for token refresh to work, the token store must contain [refresh tokens](/entra/identity-platform/refresh-tokens) for your provider. The way to get refresh tokens is documented by each provider, but the following list is a brief summary:
39
-
40
-
-**Google**: Append an `access_type=offline` query string parameter to your `/.auth/login/google` API call. For more information, see [Google Refresh Tokens](https://developers.google.com/identity/protocols/OpenIDConnect#refresh-tokens).
41
-
-**Facebook**: Doesn't provide refresh tokens. Long-lived tokens expire in 60 days (see [Long-Lived Access Tokens](https://developers.facebook.com/docs/facebook-login/guides/access-tokens/get-long-lived/)).
42
-
-**X**: Access tokens don't expire (see [OAuth FAQ](https://developer.x.com/en/docs/authentication/faq)).
43
-
-**Microsoft**: In [https://resources.azure.com](https://resources.azure.com), do the following steps:
44
-
1. At the top of the pane, select **Read/Write**.
45
-
1. On the explorer menu, go to **subscriptions** > *subscription name* > **resourceGroups** > *resource group name* > **providers** > **Microsoft.Web** > **sites** > *app name* > **config** > **authsettingsV2**.
The following information refers to provider tokens. For session tokens, see [Extend session token expiration grace period](#extend-session-token-expiration-grace-period).
60
39
61
-
> [!NOTE]
62
-
> The scope that gives you a refresh token is [offline_access](../active-directory/develop/v2-permissions-and-consent.md#offline_access). See how it's used in [Tutorial: Authenticate and authorize users end to end in Azure App Service](tutorial-auth-aad.md). The other scopes are already requested by App Service by default. For information on these default scopes, see [OpenID Connect Scopes](../active-directory/develop/v2-permissions-and-consent.md#openid-connect-scopes).
63
-
64
-
After your provider is configured, you can [find the refresh token and the expiration time for the access token](#retrieve-tokens-in-app-code) in the token store.
40
+
If your provider's access token expires, you must reauthenticate the user before you can use that token again. You can avoid token expiration by making a `GET` call to the `/.auth/refresh` endpoint of your application.
65
41
66
42
To refresh your access token at any time, call `/.auth/refresh` in any language. The following snippet uses jQuery to refresh your access tokens from a JavaScript client.
67
43
@@ -76,23 +52,48 @@ function refreshTokens() {
76
52
}
77
53
```
78
54
79
-
If a user revokes the permissions granted to your app, your call to `/.auth/me` might fail with a `403 Forbidden` response. To diagnose errors, check your application logs for details.
55
+
When called, App Service automatically refreshes the access tokens in the [token store](overview-authentication-authorization.md#token-store) for the authenticated user. Subsequent requests for tokens get the refreshed tokens. You can see the refresh tokens and the expiration time for the tokens by using the headers listed in [Retrieve tokens in app code](#retrieve-tokens-in-app-code).
56
+
57
+
>[!NOTE]
58
+
>If a user revokes the permissions they granted to your app, your call to `/.auth/me` might fail with a `403 Forbidden` response. To diagnose errors, check your application logs for details.
59
+
60
+
### Configure providers to supply refresh tokens
61
+
62
+
For token refresh to work, the token store must contain [refresh tokens](/entra/identity-platform/refresh-tokens) from your provider. Each provider documents how to get their refresh tokens. The following table provides a brief summary:
63
+
64
+
| Provider | Refresh tokens |
65
+
|-|-|
66
+
| Microsoft | Follow the procedure in [Configure the Microsoft Entra provider to supply refresh tokens](#configure-the-microsoft-entra-provider-to-supply-refresh-tokens). |
67
+
| Facebook | Doesn't provide refresh tokens. Long-lived tokens expire in 60 days. For more information, see [Long-Lived Access Tokens](https://developers.facebook.com/docs/facebook-login/guides/access-tokens/get-long-lived/). |
68
+
| Google | Append an `access_type=offline` query string parameter to your `/.auth/login/google` API call. For more information, see [Google Refresh Tokens](https://developers.google.com/identity/protocols/OpenIDConnect#refresh-tokens).|
69
+
| X | Access tokens don't expire. For more information, see [OAuth FAQ](https://developer.x.com/en/docs/authentication/faq). |
70
+
71
+
#### Configure the Microsoft Entra provider to supply refresh tokens
72
+
73
+
1. In the Azure portal, go to the [API Playground (preview)](https://portal.azure.com/#view/Microsoft_Azure_Resources/ArmPlayground), and select **New request** if necessary.
74
+
1. In the **Enter ARM relative path here including API version** field, enter the following string, replacing the placeholders with your subscription ID, resource group name, and app name:<br>`subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.Web/sites/<app-name>/config/authsettingsV2?api-version=2024-11-01`
75
+
1. Select **Execute**.
76
+
1. Select `PUT` at upper left, and select the **Request body** tab.
77
+
1. Copy the `GET` response contents from the **Response body** field and paste them into the **Request body** tab.
78
+
1. In the code, locate the `"identityProviders":`**>**`"azureActiveDirectory":`**>**`"login":` section, and add the following line:<br>`"loginParameters": ["scope=openid profile email offline_access"]`
79
+
1. Select **Execute**. The **Response body** field shows your changes.
80
+
81
+
[Offline_access](/entra/identity-platform/scopes-oidc#the-offline_access-scope) is the scope that provides refresh tokens. App Service already requests the other scopes by default. For more information, see [OpenID Connect Scopes](/entra/identity-platform/scopes-oidc#openid-connect-scopes) and [Web Apps - Update Auth Settings V2](/rest/api/appservice/web-apps/update-auth-settings-v-2).
80
82
81
83
## Extend session token expiration grace period
82
84
83
-
The authenticated session expires after 8 hours. After an authenticated session expires, a 72-hour grace period follows by default. Within this grace period, you're allowed to refresh the session token with App Service without reauthenticating the user. You can just call `/.auth/refresh` when your session token becomes invalid, and you don't need to track token expiration yourself. When the 72-hour grace period lapses, the user must sign in again to get a valid session token.
85
+
The authenticated session expires after 8 hours, and a 72-hour default grace period follows. Within this grace period, you can refresh the session token with App Service without reauthenticating the user. You can simply call `/.auth/refresh` when your session token becomes invalid, and you don't need to track token expiration yourself.
84
86
85
-
If 72 hours isn't enough time for you, you can extend this expiration window. Extending the expiration over a long period could have significant security implications (such as when an authentication token is leaked or stolen). We recommend that you leave the setting at the default 72 hours or set the extension period to the smallest value.
87
+
When the 72-hour grace period lapses, the user must sign in again to get a valid session token. If you need a longer expiration window than 72 hours, you can extend it, but extending the expiration for a long period could have significant security implications if an authentication token is leaked or stolen. It's best to leave the setting at the default 72 hours or set the extension period to the smallest possible value.
86
88
87
-
To extend the default expiration window, run the following command in [Azure Cloud Shell](../cloud-shell/overview.md).
89
+
To extend the default expiration window, run the following Azure CLI command in [Azure Cloud Shell](../cloud-shell/overview.md):
88
90
89
91
```azurecli-interactive
90
92
az webapp auth update --resource-group <group_name> --name <app_name> --token-refresh-extension-hours <hours>
91
93
```
92
94
93
95
> [!NOTE]
94
-
> The grace period only applies to the App Service authenticated session, not to the tokens from the identity providers. No grace period exists for expired provider tokens.
95
-
>
96
+
> The grace period applies only to the App Service authenticated session, not to the access tokens from the identity providers. No grace period exists for expired provider tokens.
0 commit comments