Skip to content

Commit d18f79b

Browse files
committed
touchups
1 parent 7f78cd4 commit d18f79b

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

articles/app-service/configure-authentication-user-identities.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,31 @@
22
title: Work with User Identities in AuthN/AuthZ
33
description: Learn how to access user identities when you use the built-in authentication and authorization in Azure App Service.
44
ms.topic: how-to
5-
ms.date: 07/01/2025
5+
ms.date: 07/02/2025
66
ms.custom: AppServiceIdentity
77
author: cephalin
88
ms.author: cephalin
99
---
1010

1111
# Work with user identities in Azure App Service authentication
1212

13-
This article shows you how to work with user identities when you use built-in [authentication and authorization in Azure App Service](overview-authentication-authorization.md).
13+
This article shows you how to work with user identities when you use [built-in authentication and authorization](overview-authentication-authorization.md) in Azure App Service.
14+
15+
## Prerequisites
16+
17+
A web application running on Azure App Service that has the [App Service authentication/authorization module enabled](scenario-secure-app-authentication-app-service.md).
1418

1519
## Access user claims in app code
1620

17-
Your app's authenticated end users or client applications make claims in incoming tokens. App Service makes the claims available to your code by injecting them into request headers. External requests aren't allowed to set these headers, so they're present only if set by App Service.
21+
Your app's authenticated end users or client applications make claims in incoming tokens. App Service makes the claims available to your code by injecting them into request headers. External requests aren't allowed to set these headers, so they're present only if App Service sets them.
1822

19-
You can use the claims information that App Service authentication makes available to perform authorization checks in your app code. Code in any language or framework can get needed information from the request headers. Some code frameworks provide extra options that might be more convenient. See [Framework-specific alternatives](#framework-specific-alternatives).
23+
You can use the claims information that App Service authentication provides to perform authorization checks in your app code. Code in any language or framework can get needed information from the request headers. Some code frameworks provide extra options that might be more convenient. See [Framework-specific alternatives](#framework-specific-alternatives).
2024

2125
The following table describes some example headers:
2226

2327
| Header | Description |
2428
|------------------------------|-----------------------------------------------------------------------|
25-
| `X-MS-CLIENT-PRINCIPAL` | A Base64-encoded JSON representation of available claims. For more information, see [Decode the X-MS-CLIENT-PRINCIPAL header](#decode-the-client-principal-header). |
29+
| `X-MS-CLIENT-PRINCIPAL` | A Base64-encoded JSON representation of available claims. For more information, see [Decode the client principal header](#decode-the-client-principal-header). |
2630
| `X-MS-CLIENT-PRINCIPAL-ID` | An identifier that the identity provider sets for the caller. |
2731
| `X-MS-CLIENT-PRINCIPAL-NAME` | A human-readable name that the identity provider sets for the caller, such as an email address or user principal name. |
2832
| `X-MS-CLIENT-PRINCIPAL-IDP` | The name of the identity provider that App Service authentication uses. |
@@ -32,13 +36,12 @@ Similar headers expose [provider tokens](configure-authentication-oauth-tokens.m
3236
> [!NOTE]
3337
> App Service makes the request headers available to all language frameworks. Different language frameworks might present these headers to the app code in different formats, such as lowercase or title case.
3438
35-
<a name="decode-the-client-principal-header"></a>
36-
### Decode the X-MS-CLIENT-PRINCIPAL header
39+
### Decode the client principal header
3740

3841
The `X-MS-CLIENT-PRINCIPAL` header contains the full set of available claims in Base64-encoded JSON. To process this header, your app must decode the payload and iterate through the `claims` array to find relevant claims.
3942

4043
> [!NOTE]
41-
> These claims undergo a default claims-mapping process, so some might have different names than if you process the token directly.
44+
> These claims undergo a default claims-mapping process, so some names might be different than they appear in the tokens.
4245
4346
The decoded payload structure is as follows:
4447

@@ -56,6 +59,8 @@ The decoded payload structure is as follows:
5659
}
5760
```
5861

62+
The following table describes the properties.
63+
5964
| Property | Type | Description |
6065
|------------|------------------|---------------------------------------|
6166
| `auth_typ` | string | The name of the identity provider that App Service authentication uses. |
@@ -65,7 +70,7 @@ The decoded payload structure is as follows:
6570
| `name_typ` | string | The name claim type, which is typically a URI that provides scheme information about the `name` claim if one is defined. |
6671
| `role_typ` | string | The role claim type, which is typically a URI that provides scheme information about the `role` claim if one is defined. |
6772

68-
For convenience, you can convert claims into a representation that the app's language framework uses. The following example uses C# to construct a [`ClaimsPrincipal`](/dotnet/api/system.security.claims.claimsprincipal) type for the app to use.
73+
For convenience, you can convert claims into a representation that the app's language framework uses. The following C# example constructs a [`ClaimsPrincipal`](/dotnet/api/system.security.claims.claimsprincipal) type for the app to use.
6974

7075
```csharp
7176
using System;
@@ -113,7 +118,7 @@ public static class ClaimsPrincipalParser
113118
```
114119
At this point, the code can iterate through `principal.Claims` to check claims as part of validation. Alternatively, you can convert `principal.Claims` into a standard object and use it to do those checks later in the request pipeline. You can also use that object to associate user data and for other uses.
115120

116-
The rest of this function performs this conversion to create a `ClaimsPrincipal` that can be used in other .NET code.
121+
The rest of the function performs this conversion to create a `ClaimsPrincipal` that can be used in other .NET code.
117122

118123
```csharp
119124
var identity = new ClaimsIdentity(principal.IdentityProvider, principal.NameClaimType, principal.RoleClaimType);
@@ -126,15 +131,15 @@ The rest of this function performs this conversion to create a `ClaimsPrincipal`
126131

127132
### Framework-specific alternatives
128133

129-
- For ASP.NET 4.6 apps, App Service populates [`ClaimsPrincipal.Current`](/dotnet/api/system.security.claims.claimsprincipal.current) with the authenticated user's claims. You can follow the standard .NET code pattern, including the [`Authorize`] attribute.
134+
- For ASP.NET 4.6 apps, App Service populates [`ClaimsPrincipal.Current`](/dotnet/api/system.security.claims.claimsprincipal.current) with the authenticated user's claims. You can follow the standard .NET code pattern, including the `[Authorize]` attribute.
130135

136+
`ClaimsPrincipal.Current` isn't populated for .NET code in [Azure Functions](../azure-functions/functions-overview.md), but you can still find the user claims in the request headers, or get the `ClaimsPrincipal` object from the request context or through a binding parameter. For more information, see [Work with client identities in Azure Functions](../azure-functions/functions-bindings-http-webhook-trigger.md#working-with-client-identities).
137+
131138
- For PHP apps, App Service similarly populates the `_SERVER['REMOTE_USER']` variable.
132139

133-
- For Java apps, the claims are [accessible from the Tomcat servlet](configure-language-java-security.md#authenticate-users-easy-auth).
134-
135-
- For [Azure Functions](../azure-functions/functions-overview.md), `ClaimsPrincipal.Current` isn't populated for .NET code, but you can still find the user claims in the request headers, or get the `ClaimsPrincipal` object from the request context or through a binding parameter. For more information, see [Work with client identities in Azure Functions](../azure-functions/functions-bindings-http-webhook-trigger.md#working-with-client-identities).
140+
- For Java apps, the claims are accessible from the [Tomcat servlet](configure-language-java-security.md?pivots=java-tomcat#authenticate-users-easy-auth).
136141

137-
- For .NET Core, [`Microsoft.Identity.Web`](https://www.nuget.org/packages/Microsoft.Identity.Web/) supports populating the current user with App Service authentication. For more information, see [Integration with Azure App Services authentication of web Apps running with Microsoft.Identity.Web](https://github.com/AzureAD/microsoft-identity-web/wiki/1.2.0#integration-with-azure-app-services-authentication-of-web-apps-running-with-microsoftidentityweb). For a demonstration of a web app accessing Microsoft Graph, see [Tutorial: Access Microsoft Graph from a secured .NET app as the user](scenario-secure-app-access-microsoft-graph-as-user.md).
142+
- For .NET Core, [`Microsoft.Identity.Web`](https://www.nuget.org/packages/Microsoft.Identity.Web/) supports populating the current user with App Service authentication. For more information, see [Integration with Azure App Services authentication of web apps running with Microsoft.Identity.Web](https://github.com/AzureAD/microsoft-identity-web/wiki/1.2.0#integration-with-azure-app-services-authentication-of-web-apps-running-with-microsoftidentityweb). For a demonstration of a web app accessing Microsoft Graph, see [Tutorial: Access Microsoft Graph from a secured .NET app as the user](scenario-secure-app-access-microsoft-graph-as-user.md).
138143

139144
> [!NOTE]
140145
> For claims mapping to work, you must enable the [token store](overview-authentication-authorization.md#token-store) for your app.

0 commit comments

Comments
 (0)