|
|
@ -87,7 +87,7 @@ public class AuthorizationController : Controller |
|
|
{ |
|
|
{ |
|
|
return Forbid( |
|
|
return Forbid( |
|
|
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme, |
|
|
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme, |
|
|
properties: new AuthenticationProperties(new Dictionary<string, string> |
|
|
properties: new AuthenticationProperties(new Dictionary<string, string?> |
|
|
{ |
|
|
{ |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.Error] = Errors.LoginRequired, |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.Error] = Errors.LoginRequired, |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] = "The user is not logged in." |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] = "The user is not logged in." |
|
|
@ -113,7 +113,7 @@ public class AuthorizationController : Controller |
|
|
{ |
|
|
{ |
|
|
return Forbid( |
|
|
return Forbid( |
|
|
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme, |
|
|
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme, |
|
|
properties: new AuthenticationProperties(new Dictionary<string, string> |
|
|
properties: new AuthenticationProperties(new Dictionary<string, string?> |
|
|
{ |
|
|
{ |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.Error] = Errors.InvalidRequest, |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.Error] = Errors.InvalidRequest, |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] = |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] = |
|
|
@ -151,7 +151,7 @@ public class AuthorizationController : Controller |
|
|
throw new InvalidOperationException("The user details cannot be retrieved."); |
|
|
throw new InvalidOperationException("The user details cannot be retrieved."); |
|
|
|
|
|
|
|
|
// Retrieve the application details from the database.
|
|
|
// Retrieve the application details from the database.
|
|
|
var application = await _applicationManager.FindByClientIdAsync(request.ClientId) ?? |
|
|
var application = await _applicationManager.FindByClientIdAsync(request.ClientId!) ?? |
|
|
throw new InvalidOperationException("Details concerning the calling client application cannot be found."); |
|
|
throw new InvalidOperationException("Details concerning the calling client application cannot be found."); |
|
|
|
|
|
|
|
|
// Retrieve the permanent authorizations associated with the user and the calling client application.
|
|
|
// Retrieve the permanent authorizations associated with the user and the calling client application.
|
|
|
@ -169,7 +169,7 @@ public class AuthorizationController : Controller |
|
|
case ConsentTypes.External when authorizations.Count is 0: |
|
|
case ConsentTypes.External when authorizations.Count is 0: |
|
|
return Forbid( |
|
|
return Forbid( |
|
|
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme, |
|
|
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme, |
|
|
properties: new AuthenticationProperties(new Dictionary<string, string> |
|
|
properties: new AuthenticationProperties(new Dictionary<string, string?> |
|
|
{ |
|
|
{ |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.Error] = Errors.ConsentRequired, |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.Error] = Errors.ConsentRequired, |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] = |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] = |
|
|
@ -206,7 +206,7 @@ public class AuthorizationController : Controller |
|
|
authorization ??= await _authorizationManager.CreateAsync( |
|
|
authorization ??= await _authorizationManager.CreateAsync( |
|
|
identity: identity, |
|
|
identity: identity, |
|
|
subject : await _userManager.GetUserIdAsync(user), |
|
|
subject : await _userManager.GetUserIdAsync(user), |
|
|
client : await _applicationManager.GetIdAsync(application), |
|
|
client : (await _applicationManager.GetIdAsync(application))!, |
|
|
type : AuthorizationTypes.Permanent, |
|
|
type : AuthorizationTypes.Permanent, |
|
|
scopes : identity.GetScopes()); |
|
|
scopes : identity.GetScopes()); |
|
|
|
|
|
|
|
|
@ -221,7 +221,7 @@ public class AuthorizationController : Controller |
|
|
case ConsentTypes.Systematic when request.HasPromptValue(PromptValues.None): |
|
|
case ConsentTypes.Systematic when request.HasPromptValue(PromptValues.None): |
|
|
return Forbid( |
|
|
return Forbid( |
|
|
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme, |
|
|
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme, |
|
|
properties: new AuthenticationProperties(new Dictionary<string, string> |
|
|
properties: new AuthenticationProperties(new Dictionary<string, string?> |
|
|
{ |
|
|
{ |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.Error] = Errors.ConsentRequired, |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.Error] = Errors.ConsentRequired, |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] = |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] = |
|
|
@ -254,7 +254,7 @@ public class AuthorizationController : Controller |
|
|
throw new InvalidOperationException("The user details cannot be retrieved."); |
|
|
throw new InvalidOperationException("The user details cannot be retrieved."); |
|
|
|
|
|
|
|
|
// Retrieve the application details from the database.
|
|
|
// Retrieve the application details from the database.
|
|
|
var application = await _applicationManager.FindByClientIdAsync(request.ClientId) ?? |
|
|
var application = await _applicationManager.FindByClientIdAsync(request.ClientId!) ?? |
|
|
throw new InvalidOperationException("Details concerning the calling client application cannot be found."); |
|
|
throw new InvalidOperationException("Details concerning the calling client application cannot be found."); |
|
|
|
|
|
|
|
|
// Retrieve the permanent authorizations associated with the user and the calling client application.
|
|
|
// Retrieve the permanent authorizations associated with the user and the calling client application.
|
|
|
@ -272,7 +272,7 @@ public class AuthorizationController : Controller |
|
|
{ |
|
|
{ |
|
|
return Forbid( |
|
|
return Forbid( |
|
|
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme, |
|
|
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme, |
|
|
properties: new AuthenticationProperties(new Dictionary<string, string> |
|
|
properties: new AuthenticationProperties(new Dictionary<string, string?> |
|
|
{ |
|
|
{ |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.Error] = Errors.ConsentRequired, |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.Error] = Errors.ConsentRequired, |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] = |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] = |
|
|
@ -305,7 +305,7 @@ public class AuthorizationController : Controller |
|
|
authorization ??= await _authorizationManager.CreateAsync( |
|
|
authorization ??= await _authorizationManager.CreateAsync( |
|
|
identity: identity, |
|
|
identity: identity, |
|
|
subject : await _userManager.GetUserIdAsync(user), |
|
|
subject : await _userManager.GetUserIdAsync(user), |
|
|
client : await _applicationManager.GetIdAsync(application), |
|
|
client : (await _applicationManager.GetIdAsync(application))!, |
|
|
type : AuthorizationTypes.Permanent, |
|
|
type : AuthorizationTypes.Permanent, |
|
|
scopes : identity.GetScopes()); |
|
|
scopes : identity.GetScopes()); |
|
|
|
|
|
|
|
|
@ -333,7 +333,7 @@ public class AuthorizationController : Controller |
|
|
if (result.Succeeded && !string.IsNullOrEmpty(result.Principal.GetClaim(Claims.ClientId))) |
|
|
if (result.Succeeded && !string.IsNullOrEmpty(result.Principal.GetClaim(Claims.ClientId))) |
|
|
{ |
|
|
{ |
|
|
// Retrieve the application details from the database using the client_id stored in the principal.
|
|
|
// Retrieve the application details from the database using the client_id stored in the principal.
|
|
|
var application = await _applicationManager.FindByClientIdAsync(result.Principal.GetClaim(Claims.ClientId)) ?? |
|
|
var application = await _applicationManager.FindByClientIdAsync(result.Principal.GetClaim(Claims.ClientId)!) ?? |
|
|
throw new InvalidOperationException("Details concerning the calling client application cannot be found."); |
|
|
throw new InvalidOperationException("Details concerning the calling client application cannot be found."); |
|
|
|
|
|
|
|
|
// Render a form asking the user to confirm the authorization demand.
|
|
|
// Render a form asking the user to confirm the authorization demand.
|
|
|
@ -347,7 +347,7 @@ public class AuthorizationController : Controller |
|
|
|
|
|
|
|
|
// If a user code was specified (e.g as part of the verification_uri_complete)
|
|
|
// If a user code was specified (e.g as part of the verification_uri_complete)
|
|
|
// but is not valid, render a form asking the user to enter the user code manually.
|
|
|
// but is not valid, render a form asking the user to enter the user code manually.
|
|
|
else if (!string.IsNullOrEmpty(result.Properties.GetTokenValue(OpenIddictServerAspNetCoreConstants.Tokens.UserCode))) |
|
|
else if (!string.IsNullOrEmpty(result.Properties?.GetTokenValue(OpenIddictServerAspNetCoreConstants.Tokens.UserCode))) |
|
|
{ |
|
|
{ |
|
|
return View(new VerifyViewModel |
|
|
return View(new VerifyViewModel |
|
|
{ |
|
|
{ |
|
|
@ -462,12 +462,12 @@ public class AuthorizationController : Controller |
|
|
|
|
|
|
|
|
if (request.IsPasswordGrantType()) |
|
|
if (request.IsPasswordGrantType()) |
|
|
{ |
|
|
{ |
|
|
var user = await _userManager.FindByNameAsync(request.Username); |
|
|
var user = await _userManager.FindByNameAsync(request.Username!); |
|
|
if (user is null) |
|
|
if (user is null) |
|
|
{ |
|
|
{ |
|
|
return Forbid( |
|
|
return Forbid( |
|
|
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme, |
|
|
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme, |
|
|
properties: new AuthenticationProperties(new Dictionary<string, string> |
|
|
properties: new AuthenticationProperties(new Dictionary<string, string?> |
|
|
{ |
|
|
{ |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.Error] = Errors.InvalidGrant, |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.Error] = Errors.InvalidGrant, |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] = "The username/password couple is invalid." |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] = "The username/password couple is invalid." |
|
|
@ -475,12 +475,12 @@ public class AuthorizationController : Controller |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Validate the username/password parameters and ensure the account is not locked out.
|
|
|
// Validate the username/password parameters and ensure the account is not locked out.
|
|
|
var result = await _signInManager.CheckPasswordSignInAsync(user, request.Password, lockoutOnFailure: true); |
|
|
var result = await _signInManager.CheckPasswordSignInAsync(user, request.Password!, lockoutOnFailure: true); |
|
|
if (!result.Succeeded) |
|
|
if (!result.Succeeded) |
|
|
{ |
|
|
{ |
|
|
return Forbid( |
|
|
return Forbid( |
|
|
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme, |
|
|
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme, |
|
|
properties: new AuthenticationProperties(new Dictionary<string, string> |
|
|
properties: new AuthenticationProperties(new Dictionary<string, string?> |
|
|
{ |
|
|
{ |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.Error] = Errors.InvalidGrant, |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.Error] = Errors.InvalidGrant, |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] = "The username/password couple is invalid." |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] = "The username/password couple is invalid." |
|
|
@ -517,12 +517,12 @@ public class AuthorizationController : Controller |
|
|
var result = await HttpContext.AuthenticateAsync(OpenIddictServerAspNetCoreDefaults.AuthenticationScheme); |
|
|
var result = await HttpContext.AuthenticateAsync(OpenIddictServerAspNetCoreDefaults.AuthenticationScheme); |
|
|
|
|
|
|
|
|
// Retrieve the user profile corresponding to the authorization code/refresh token.
|
|
|
// Retrieve the user profile corresponding to the authorization code/refresh token.
|
|
|
var user = await _userManager.FindByIdAsync(result.Principal.GetClaim(Claims.Subject)); |
|
|
var user = await _userManager.FindByIdAsync(result.Principal!.GetClaim(Claims.Subject)!); |
|
|
if (user is null) |
|
|
if (user is null) |
|
|
{ |
|
|
{ |
|
|
return Forbid( |
|
|
return Forbid( |
|
|
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme, |
|
|
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme, |
|
|
properties: new AuthenticationProperties(new Dictionary<string, string> |
|
|
properties: new AuthenticationProperties(new Dictionary<string, string?> |
|
|
{ |
|
|
{ |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.Error] = Errors.InvalidGrant, |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.Error] = Errors.InvalidGrant, |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] = "The token is no longer valid." |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] = "The token is no longer valid." |
|
|
@ -534,14 +534,14 @@ public class AuthorizationController : Controller |
|
|
{ |
|
|
{ |
|
|
return Forbid( |
|
|
return Forbid( |
|
|
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme, |
|
|
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme, |
|
|
properties: new AuthenticationProperties(new Dictionary<string, string> |
|
|
properties: new AuthenticationProperties(new Dictionary<string, string?> |
|
|
{ |
|
|
{ |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.Error] = Errors.InvalidGrant, |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.Error] = Errors.InvalidGrant, |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] = "The user is no longer allowed to sign in." |
|
|
[OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] = "The user is no longer allowed to sign in." |
|
|
})); |
|
|
})); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var identity = new ClaimsIdentity(result.Principal.Claims, |
|
|
var identity = new ClaimsIdentity(result.Principal!.Claims, |
|
|
authenticationType: TokenValidationParameters.DefaultAuthenticationType, |
|
|
authenticationType: TokenValidationParameters.DefaultAuthenticationType, |
|
|
nameType: Claims.Name, |
|
|
nameType: Claims.Name, |
|
|
roleType: Claims.Role); |
|
|
roleType: Claims.Role); |
|
|
@ -575,7 +575,7 @@ public class AuthorizationController : Controller |
|
|
case Claims.Name or Claims.PreferredUsername: |
|
|
case Claims.Name or Claims.PreferredUsername: |
|
|
yield return Destinations.AccessToken; |
|
|
yield return Destinations.AccessToken; |
|
|
|
|
|
|
|
|
if (claim.Subject.HasScope(Scopes.Profile)) |
|
|
if (claim.Subject!.HasScope(Scopes.Profile)) |
|
|
yield return Destinations.IdentityToken; |
|
|
yield return Destinations.IdentityToken; |
|
|
|
|
|
|
|
|
yield break; |
|
|
yield break; |
|
|
@ -583,7 +583,7 @@ public class AuthorizationController : Controller |
|
|
case Claims.Email: |
|
|
case Claims.Email: |
|
|
yield return Destinations.AccessToken; |
|
|
yield return Destinations.AccessToken; |
|
|
|
|
|
|
|
|
if (claim.Subject.HasScope(Scopes.Email)) |
|
|
if (claim.Subject!.HasScope(Scopes.Email)) |
|
|
yield return Destinations.IdentityToken; |
|
|
yield return Destinations.IdentityToken; |
|
|
|
|
|
|
|
|
yield break; |
|
|
yield break; |
|
|
@ -591,7 +591,7 @@ public class AuthorizationController : Controller |
|
|
case Claims.Role: |
|
|
case Claims.Role: |
|
|
yield return Destinations.AccessToken; |
|
|
yield return Destinations.AccessToken; |
|
|
|
|
|
|
|
|
if (claim.Subject.HasScope(Scopes.Roles)) |
|
|
if (claim.Subject!.HasScope(Scopes.Roles)) |
|
|
yield return Destinations.IdentityToken; |
|
|
yield return Destinations.IdentityToken; |
|
|
|
|
|
|
|
|
yield break; |
|
|
yield break; |
|
|
|