Skip to content

Commit 49c8ce8

Browse files
committed
refresh content
1 parent b4b1ff6 commit 49c8ce8

1 file changed

Lines changed: 28 additions & 25 deletions

File tree

aspnetcore/security/authentication/claims.md

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
11
---
2-
title: Mapping, customizing, and transforming claims in ASP.NET Core
2+
title: Map, customize, transform claims in ASP.NET Core
33
author: damienbod
4-
description: Learn how to map claims, do claims transformations, customize claims.
4+
description: Learn how to map claims, perform claims transformations, and customize claims in your in ASP.NET Core apps.
55
monikerRange: '>= aspnetcore-3.1'
66
ms.author: wpickett
77
ms.custom: mvc
8-
ms.date: 2/16/2022
8+
ms.date: 05/15/2026
99
uid: security/authentication/claims
10+
11+
# customer intent: As an ASP.NET developer, I want to work with claims in my ASP.NET Core app, so I can map claims, do transformations, and make customizations.
1012
---
11-
# Mapping, customizing, and transforming claims in ASP.NET Core
13+
# Map, customize, and transform claims in ASP.NET Core
1214

1315
By [Damien Bowden](https://github.com/damienbod)
1416

1517
:::moniker range=">= aspnetcore-6.0"
1618

17-
Claims can be created from any user or identity data which can be issued using a trusted identity provider or ASP.NET Core identity. A claim is a name value pair that represents what the subject is, not what the subject can do.
18-
This article covers the following areas:
19+
Claims can be created from any user or identity data that can be issued by using a trusted identity provider or ASP.NET Core identity. A claim is a name-value pair that represents what the subject is, not what the subject can do.
1920

20-
* How to configure and map claims using an [OpenID Connect](https://openid.net/developers/how-connect-works/) client
21-
* Set the name and role claim
21+
This article describes how to configure and map claims by using an [OpenID Connect](https://openid.net/developers/how-connect-works/) client and covers the following tasks:
22+
23+
* Set name and role claims
2224
* Reset the claims namespaces
23-
* Customize, extend the claims using <xref:Microsoft.AspNetCore.Authentication.IClaimsTransformation.TransformAsync%2A>
25+
* Customize and extend the claims with the <xref:Microsoft.AspNetCore.Authentication.IClaimsTransformation.TransformAsync%2A> method
2426

25-
## Mapping claims using OpenID Connect authentication
27+
## Map claims with OpenID Connect authentication
2628

27-
The profile claims can be returned in the `id_token`, which is returned after a successful authentication. The ASP.NET Core client app only requires the profile scope. When using the `id_token` for claims, no extra claims mapping is required.
29+
The profile claims can be returned in the `id_token`, which is returned after a successful authentication. The ASP.NET Core client app only requires the profile scope. When you use the `id_token` for claims, no extra claims mapping is required.
2830

2931
[!code-csharp[](~/security/authentication/claims/sample6/WebRPmapClaims/Program.cs?name=snippet1&highlight=8-26)]
3032

3133
The preceding code requires the [Microsoft.AspNetCore.Authentication.OpenIdConnect](https://www.nuget.org/packages/Microsoft.AspNetCore.Authentication.OpenIdConnect) NuGet package.
3234

33-
Another way to get the user claims is to use the OpenID Connect User Info API. The ASP.NET Core client app uses the `GetClaimsFromUserInfoEndpoint` property to configure this. One important difference from the first settings, is that you must specify the claims you require using the `MapUniqueJsonKey` method, otherwise only the `name`, `given_name` and `email` standard claims will be available in the client app. The claims included in the `id_token` are mapped per default. This is the major difference to the first option. You must explicitly define some of the claims you require.
35+
Another way to get the user claims is to use the OpenID Connect User Info API. The ASP.NET Core client app uses the `GetClaimsFromUserInfoEndpoint` property to do the configuration. In this scenario, you must explicitly specify the required claims by using the `MapUniqueJsonKey` method. Otherwise, only the `name`, `given_name`, and `email` standard claims are available in the client app. The claims included in the `id_token` are mapped per default.
3436

3537
[!code-csharp[](~/security/authentication/claims/sample6/WebRPmapClaims/Program.cs?name=snippet2&highlight=26-29)]
3638

@@ -39,27 +41,27 @@ Another way to get the user claims is to use the OpenID Connect User Info API. T
3941
:::moniker range="> aspnetcore-8.0"
4042

4143
> [!NOTE]
42-
> The default Open ID Connect handler uses Pushed Authorization Requests (PAR) if the identity provider's discovery document advertises support for PAR. The identity provider's discovery document is usually found at `.well-known/openid-configuration`. If you cannot use PAR in the client configuration on the identity provider, PAR can be disabled by using the **PushedAuthorizationBehavior** option.
44+
> The default Open ID Connect handler uses Pushed Authorization Requests (PAR) if the identity provider's discovery document advertises support for PAR. The common location for the identity provider's discovery document is the _.well-known/openid-configuration_ folder. If you can't use PAR in the client configuration on the identity provider, PAR can be disabled by using the `PushedAuthorizationBehavior` option.
4345
4446
:::code language="csharp" source="~/release-notes/aspnetcore-9/samples/PAR/Program.cs" id="snippet_1" highlight="8-99":::
4547

46-
To ensure that authentication only succeeds if PAR is used, use [`PushedAuthorizationBehavior.Require`](xref:Microsoft.AspNetCore.Authentication.OpenIdConnect.PushedAuthorizationBehavior) instead. This change also introduces a new <xref:Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectEvents.OnPushAuthorization> event to <xref:Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectEvents> which can be used to customize the pushed authorization request or handle it manually. For more information, see the [API proposal](https://github.com/dotnet/aspnetcore/issues/51686).
48+
To ensure authentication succeeds only if PAR is used, use the [PushedAuthorizationBehavior.Require](xref:Microsoft.AspNetCore.Authentication.OpenIdConnect.PushedAuthorizationBehavior) enum instead. This change also introduces a new <xref:Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectEvents.OnPushAuthorization> event to <xref:Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectEvents>, which can be used to customize the pushed authorization request or handle it manually. For more information, see the [API proposal in GitHub dotnet/aspnetcore issue #51686](https://github.com/dotnet/aspnetcore/issues/51686) - _Support for Pushed Authorization Requests in OidcHandler_.
4749

4850
:::moniker-end
4951

5052
:::moniker range=">= aspnetcore-6.0"
5153

5254
## Name claim and role claim mapping
5355

54-
The **Name** claim and the **Role** claim are mapped to default properties in the ASP.NET Core HTTP context. Sometimes it is required to use different claims for the default properties, or the name claim and the role claim do not match the default values. The claims can be mapped using the **TokenValidationParameters** property and set to any claim as required. The values from the claims can be used directly in the HttpContext **User.Identity.Name** property and the roles.
56+
The **name** claim and **role** claim are mapped to default properties in the ASP.NET Core HTTP context. Sometimes, you need to use different claims for the default properties, or the name claim and role claim don't match the default values. The claims can be mapped by using the `TokenValidationParameters` property and set to any claim as required. The values from the claims can be used directly in the HttpContext `User.Identity.Name` property and the roles.
5557

56-
If the `User.Identity.Name` has no value or the roles are missing, please check the values in the returned claims and set the `NameClaimType` and the `RoleClaimType` values. The returned claims from the client authentication can be viewed in the HTTP context.
58+
If the `User.Identity.Name` property has no value, or the roles are missing, check the values in the returned claims and set the `NameClaimType` and the `RoleClaimType` values. The returned claims from the client authentication can be viewed in the HTTP context.
5759

5860
[!code-csharp[](~/security/authentication/claims/sample6/WebRPmapClaims/Program.cs?name=snippet_name&highlight=10-14)]
5961

6062
## Claims namespaces, default namespaces
6163

62-
ASP.NET Core adds default namespaces to some known claims, which might not be required in the app. Optionally, disable these added namespaces and use the exact claims that the OpenID Connect server created.
64+
ASP.NET Core adds default namespaces to some known claims. The default claims might not be required in the app. As an option, you can disable the added namespaces and use the exact claims that the OpenID Connect server created.
6365

6466
:::moniker-end
6567

@@ -68,7 +70,6 @@ ASP.NET Core adds default namespaces to some known claims, which might not be re
6870
[!code-csharp[](~/security/authentication/claims/sample8/WebRPmapClaims/Program.cs?name=snippet_NS&highlight=5)]
6971

7072
:::moniker-end
71-
7273
:::moniker range=">= aspnetcore-6.0 < aspnetcore-8.0"
7374

7475
[!code-csharp[](~/security/authentication/claims/sample6/WebRPmapClaims/Program.cs?name=snippet_NS&highlight=5)]
@@ -77,13 +78,13 @@ ASP.NET Core adds default namespaces to some known claims, which might not be re
7778

7879
:::moniker range=">= aspnetcore-6.0"
7980

80-
If you need to disable the namespaces per scheme and not globally, you can use the **MapInboundClaims = false** option.
81+
If you need to disable the namespaces per scheme and not globally, you can use the `MapInboundClaims = false` option.
8182

8283
[!code-csharp[](~/security/authentication/claims/sample8/WebRPmapClaims/Program.cs?name=snippet_NS8&highlight=20)]
8384

84-
## Extend or add custom claims using `IClaimsTransformation`
85+
## Extend or add custom claims using 'IClaimsTransformation'
8586

86-
The <xref:Microsoft.AspNetCore.Authentication.IClaimsTransformation> interface can be used to add extra claims to the <xref:System.Security.Claims.ClaimsPrincipal> class. The interface requires a single method <xref:Microsoft.AspNetCore.Authentication.IClaimsTransformation.TransformAsync%2A>. This method might get called multiple times. Only add a new claim if it does not already exist in the `ClaimsPrincipal`. A `ClaimsIdentity` is created to add the new claims and this can be added to the `ClaimsPrincipal`.
87+
The <xref:Microsoft.AspNetCore.Authentication.IClaimsTransformation> interface can be used to add extra claims to the <xref:System.Security.Claims.ClaimsPrincipal> class. The interface requires a single method, <xref:Microsoft.AspNetCore.Authentication.IClaimsTransformation.TransformAsync%2A>. This method might be called multiple times. Only add a new claim if it doesn't already exist in the `ClaimsPrincipal`. A `ClaimsIdentity` object is created to add the new claims and it can be added to the `ClaimsPrincipal`.
8788

8889
[!code-csharp[](~/security/authentication/claims/sample6/WebRPmapClaims/MyClaimsTransformation.cs)]
8990

@@ -103,13 +104,10 @@ Refer to the following document:
103104

104105
## Map claims from external identity providers
105106

106-
Refer to the following document:
107-
108-
[Persist additional claims and tokens from external providers in ASP.NET Core](xref:security/authentication/social/additional-claims)
107+
If you want to map claims from external identity providers for your app, see [Persist other claims and tokens from external providers in ASP.NET Core](xref:security/authentication/social/additional-claims).
109108

110109
:::moniker-end
111110

112-
113111
:::moniker range="< aspnetcore-6.0"
114112

115113
Claims can be created from any user or identity data which can be issued using a trusted identity provider or ASP.NET Core identity. A claim is a name value pair that represents what the subject is, not what the subject can do.
@@ -254,3 +252,8 @@ Refer to the following document:
254252
[Persist additional claims and tokens from external providers in ASP.NET Core](xref:security/authentication/social/additional-claims)
255253

256254
:::moniker-end
255+
256+
## Related content
257+
258+
- <xref:Microsoft.AspNetCore.Authentication.IClaimsTransformation>
259+
- <xref:System.Security.Claims.ClaimsPrincipal>

0 commit comments

Comments
 (0)