|
|
|
@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Authorization; |
|
|
|
using Microsoft.AspNetCore.Identity; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.Extensions.Primitives; |
|
|
|
using Microsoft.IdentityModel.Tokens; |
|
|
|
using OpenIddict.Abstractions; |
|
|
|
using OpenIddict.Client.AspNetCore; |
|
|
|
using OpenIddict.Sandbox.AspNetCore.Server.Helpers; |
|
|
|
@ -172,11 +173,16 @@ public class AuthorizationController : Controller |
|
|
|
case ConsentTypes.External when authorizations.Any(): |
|
|
|
case ConsentTypes.Explicit when authorizations.Any() && !request.HasPrompt(Prompts.Consent): |
|
|
|
// Create the claims-based identity that will be used by OpenIddict to generate tokens.
|
|
|
|
var identity = new ClaimsIdentity(OpenIddictServerAspNetCoreDefaults.AuthenticationScheme) |
|
|
|
.AddClaim(Claims.Subject, await _userManager.GetUserIdAsync(user)) |
|
|
|
.AddClaim(Claims.Email, await _userManager.GetEmailAsync(user)) |
|
|
|
.AddClaim(Claims.Name, await _userManager.GetUserNameAsync(user)) |
|
|
|
.AddClaims(Claims.Role, (await _userManager.GetRolesAsync(user)).ToImmutableArray()); |
|
|
|
var identity = new ClaimsIdentity( |
|
|
|
authenticationType: TokenValidationParameters.DefaultAuthenticationType, |
|
|
|
nameType: Claims.Name, |
|
|
|
roleType: Claims.Role); |
|
|
|
|
|
|
|
// Add the claims that will be persisted in the tokens.
|
|
|
|
identity.AddClaim(Claims.Subject, await _userManager.GetUserIdAsync(user)) |
|
|
|
.AddClaim(Claims.Email, await _userManager.GetEmailAsync(user)) |
|
|
|
.AddClaim(Claims.Name, await _userManager.GetUserNameAsync(user)) |
|
|
|
.AddClaims(Claims.Role, (await _userManager.GetRolesAsync(user)).ToImmutableArray()); |
|
|
|
|
|
|
|
// Note: in this sample, the granted scopes match the requested scope
|
|
|
|
// but you may want to allow the user to uncheck specific scopes.
|
|
|
|
@ -263,11 +269,16 @@ public class AuthorizationController : Controller |
|
|
|
} |
|
|
|
|
|
|
|
// Create the claims-based identity that will be used by OpenIddict to generate tokens.
|
|
|
|
var identity = new ClaimsIdentity(OpenIddictServerAspNetCoreDefaults.AuthenticationScheme) |
|
|
|
.AddClaim(Claims.Subject, await _userManager.GetUserIdAsync(user)) |
|
|
|
.AddClaim(Claims.Email, await _userManager.GetEmailAsync(user)) |
|
|
|
.AddClaim(Claims.Name, await _userManager.GetUserNameAsync(user)) |
|
|
|
.AddClaims(Claims.Role, (await _userManager.GetRolesAsync(user)).ToImmutableArray()); |
|
|
|
var identity = new ClaimsIdentity( |
|
|
|
authenticationType: TokenValidationParameters.DefaultAuthenticationType, |
|
|
|
nameType: Claims.Name, |
|
|
|
roleType: Claims.Role); |
|
|
|
|
|
|
|
// Add the claims that will be persisted in the tokens.
|
|
|
|
identity.AddClaim(Claims.Subject, await _userManager.GetUserIdAsync(user)) |
|
|
|
.AddClaim(Claims.Email, await _userManager.GetEmailAsync(user)) |
|
|
|
.AddClaim(Claims.Name, await _userManager.GetUserNameAsync(user)) |
|
|
|
.AddClaims(Claims.Role, (await _userManager.GetRolesAsync(user)).ToImmutableArray()); |
|
|
|
|
|
|
|
// Note: in this sample, the granted scopes match the requested scope
|
|
|
|
// but you may want to allow the user to uncheck specific scopes.
|
|
|
|
@ -355,11 +366,16 @@ public class AuthorizationController : Controller |
|
|
|
if (result.Succeeded) |
|
|
|
{ |
|
|
|
// Create the claims-based identity that will be used by OpenIddict to generate tokens.
|
|
|
|
var identity = new ClaimsIdentity(OpenIddictServerAspNetCoreDefaults.AuthenticationScheme) |
|
|
|
.AddClaim(Claims.Subject, await _userManager.GetUserIdAsync(user)) |
|
|
|
.AddClaim(Claims.Email, await _userManager.GetEmailAsync(user)) |
|
|
|
.AddClaim(Claims.Name, await _userManager.GetUserNameAsync(user)) |
|
|
|
.AddClaims(Claims.Role, (await _userManager.GetRolesAsync(user)).ToImmutableArray()); |
|
|
|
var identity = new ClaimsIdentity( |
|
|
|
authenticationType: TokenValidationParameters.DefaultAuthenticationType, |
|
|
|
nameType: Claims.Name, |
|
|
|
roleType: Claims.Role); |
|
|
|
|
|
|
|
// Add the claims that will be persisted in the tokens.
|
|
|
|
identity.AddClaim(Claims.Subject, await _userManager.GetUserIdAsync(user)) |
|
|
|
.AddClaim(Claims.Email, await _userManager.GetEmailAsync(user)) |
|
|
|
.AddClaim(Claims.Name, await _userManager.GetUserNameAsync(user)) |
|
|
|
.AddClaims(Claims.Role, (await _userManager.GetRolesAsync(user)).ToImmutableArray()); |
|
|
|
|
|
|
|
// Note: in this sample, the granted scopes match the requested scope
|
|
|
|
// but you may want to allow the user to uncheck specific scopes.
|
|
|
|
@ -464,11 +480,16 @@ public class AuthorizationController : Controller |
|
|
|
} |
|
|
|
|
|
|
|
// Create the claims-based identity that will be used by OpenIddict to generate tokens.
|
|
|
|
var identity = new ClaimsIdentity(OpenIddictServerAspNetCoreDefaults.AuthenticationScheme) |
|
|
|
.AddClaim(Claims.Subject, await _userManager.GetUserIdAsync(user)) |
|
|
|
.AddClaim(Claims.Email, await _userManager.GetEmailAsync(user)) |
|
|
|
.AddClaim(Claims.Name, await _userManager.GetUserNameAsync(user)) |
|
|
|
.AddClaims(Claims.Role, (await _userManager.GetRolesAsync(user)).ToImmutableArray()); |
|
|
|
var identity = new ClaimsIdentity( |
|
|
|
authenticationType: TokenValidationParameters.DefaultAuthenticationType, |
|
|
|
nameType: Claims.Name, |
|
|
|
roleType: Claims.Role); |
|
|
|
|
|
|
|
// Add the claims that will be persisted in the tokens.
|
|
|
|
identity.AddClaim(Claims.Subject, await _userManager.GetUserIdAsync(user)) |
|
|
|
.AddClaim(Claims.Email, await _userManager.GetEmailAsync(user)) |
|
|
|
.AddClaim(Claims.Name, await _userManager.GetUserNameAsync(user)) |
|
|
|
.AddClaims(Claims.Role, (await _userManager.GetRolesAsync(user)).ToImmutableArray()); |
|
|
|
|
|
|
|
// Note: in this sample, the granted scopes match the requested scope
|
|
|
|
// but you may want to allow the user to uncheck specific scopes.
|
|
|
|
|