Browse Source

Add specific error codes for Authentication failures in OpenIddict TokenController.Password

pull/20716/head
Ali Hassan 2 years ago
parent
commit
6d81e93ccb
  1. 7
      modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.Password.cs

7
modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.Password.cs

@ -108,10 +108,13 @@ public partial class TokenController
}); });
string errorDescription; string errorDescription;
string errorCode;
if (result.IsLockedOut) if (result.IsLockedOut)
{ {
Logger.LogInformation("Authentication failed for username: {username}, reason: locked out", request.Username); Logger.LogInformation("Authentication failed for username: {username}, reason: locked out", request.Username);
errorDescription = "The user account has been locked out due to invalid login attempts. Please wait a while and try again."; errorDescription = "The user account has been locked out due to invalid login attempts. Please wait a while and try again.";
errorCode = "account_locked";
} }
else if (result.IsNotAllowed) else if (result.IsNotAllowed)
{ {
@ -128,16 +131,18 @@ public partial class TokenController
} }
errorDescription = "You are not allowed to login! Your account is inactive or needs to confirm your email/phone number."; errorDescription = "You are not allowed to login! Your account is inactive or needs to confirm your email/phone number.";
errorCode = "account_inactive";
} }
else else
{ {
Logger.LogInformation("Authentication failed for username: {username}, reason: invalid credentials", request.Username); Logger.LogInformation("Authentication failed for username: {username}, reason: invalid credentials", request.Username);
errorDescription = "Invalid username or password!"; errorDescription = "Invalid username or password!";
errorCode = OpenIddictConstants.Errors.InvalidGrant;
} }
var properties = new AuthenticationProperties(new Dictionary<string, string> var properties = new AuthenticationProperties(new Dictionary<string, string>
{ {
[OpenIddictServerAspNetCoreConstants.Properties.Error] = OpenIddictConstants.Errors.InvalidGrant, [OpenIddictServerAspNetCoreConstants.Properties.Error] = errorCode,
[OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] = errorDescription [OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] = errorDescription
}); });

Loading…
Cancel
Save