@@ -90,24 +90,21 @@ public async Task<IActionResult> Accept(CancellationToken cancellationToken)
90
90
91
91
// Create a new ClaimsIdentity containing the claims that
92
92
// will be used to create an id_token, a token or a code.
93
- var identity = new ClaimsIdentity ( OpenIdConnectServerDefaults . AuthenticationScheme ) ;
94
-
95
- // Copy the claims retrieved from the external identity provider
96
- // (e.g Google, Facebook, a WS-Fed provider or another OIDC server).
97
- foreach ( var claim in HttpContext . User . Claims )
98
- {
99
- // Allow ClaimTypes.Name to be added in the id_token.
100
- // ClaimTypes.NameIdentifier is automatically added, even if its
101
- // destination is not defined or doesn't include "id_token".
102
- // The other claims won't be visible for the client application.
103
- if ( claim . Type == ClaimTypes . Name )
104
- {
105
- claim . SetDestinations ( OpenIdConnectConstants . Destinations . AccessToken ,
106
- OpenIdConnectConstants . Destinations . IdentityToken ) ;
107
- }
108
-
109
- identity . AddClaim ( claim ) ;
110
- }
93
+ var identity = new ClaimsIdentity (
94
+ OpenIdConnectServerDefaults . AuthenticationScheme ,
95
+ OpenIdConnectConstants . Claims . Name ,
96
+ OpenIdConnectConstants . Claims . Role ) ;
97
+
98
+ // Note: the "sub" claim is mandatory and an exception is thrown if this claim is missing.
99
+ identity . AddClaim (
100
+ new Claim ( OpenIdConnectConstants . Claims . Subject , User . FindFirst ( ClaimTypes . NameIdentifier ) . Value )
101
+ . SetDestinations ( OpenIdConnectConstants . Destinations . AccessToken ,
102
+ OpenIdConnectConstants . Destinations . IdentityToken ) ) ;
103
+
104
+ identity . AddClaim (
105
+ new Claim ( OpenIdConnectConstants . Claims . Name , User . FindFirst ( ClaimTypes . Name ) . Value )
106
+ . SetDestinations ( OpenIdConnectConstants . Destinations . AccessToken ,
107
+ OpenIdConnectConstants . Destinations . IdentityToken ) ) ;
111
108
112
109
var application = await GetApplicationAsync ( request . ClientId , cancellationToken ) ;
113
110
if ( application == null )
@@ -129,7 +126,8 @@ public async Task<IActionResult> Accept(CancellationToken cancellationToken)
129
126
// Note: this sample always grants the "openid", "email" and "profile" scopes
130
127
// when they are requested by the client application: a real world application
131
128
// would probably display a form allowing to select the scopes to grant.
132
- ticket . SetScopes ( new [ ] {
129
+ ticket . SetScopes ( new [ ]
130
+ {
133
131
/* openid: */ OpenIdConnectConstants . Scopes . OpenId ,
134
132
/* email: */ OpenIdConnectConstants . Scopes . Email ,
135
133
/* profile: */ OpenIdConnectConstants . Scopes . Profile ,
@@ -140,8 +138,6 @@ public async Task<IActionResult> Accept(CancellationToken cancellationToken)
140
138
ticket . SetResources ( "resource_server" ) ;
141
139
142
140
// Returning a SignInResult will ask ASOS to serialize the specified identity to build appropriate tokens.
143
- // Note: you should always make sure the identities you return contain ClaimTypes.NameIdentifier claim.
144
- // In this sample, the identity always contains the name identifier returned by the external provider.
145
141
return SignIn ( ticket . Principal , ticket . Properties , ticket . AuthenticationScheme ) ;
146
142
}
147
143
0 commit comments