Browse Source

Merge pull request #20716 from alihdev/login_failed_error_code

Add Specific Error Codes for Authentication Failures
pull/23315/head
maliming 1 year ago
committed by GitHub
parent
commit
81f9296e6e
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 8
      modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/AbpOpenIddictErrors.cs
  2. 8
      modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.Password.cs

8
modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/AbpOpenIddictErrors.cs

@ -0,0 +1,8 @@
namespace Volo.Abp.OpenIddict;
public static class AbpOpenIddictErrors
{
public const string AccountLocked = "account_locked";
public const string AccountInactive = "account_inactive";
}

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

@ -107,10 +107,13 @@ public partial class TokenController
ClientId = request.ClientId
});
var errorCode = OpenIddictConstants.Errors.InvalidGrant;
string errorDescription;
if (result.IsLockedOut)
{
Logger.LogInformation("Authentication failed for username: {username}, reason: locked out", request.Username);
errorCode = AbpOpenIddictErrors.AccountLocked;
errorDescription = "The user account has been locked out due to invalid login attempts. Please wait a while and try again.";
}
else if (result.IsNotAllowed)
@ -139,7 +142,8 @@ public partial class TokenController
return await HandleConfirmUserAsync(request, user);
}
errorDescription = "You are not allowed to login! Your account is inactive.";
errorCode = AbpOpenIddictErrors.AccountInactive;
errorDescription = "You are not allowed to login! Your account is inactive or needs to confirm your email/phone number.";
}
}
else
@ -150,7 +154,7 @@ public partial class TokenController
var properties = new AuthenticationProperties(new Dictionary<string, string>
{
[OpenIddictServerAspNetCoreConstants.Properties.Error] = OpenIddictConstants.Errors.InvalidGrant,
[OpenIddictServerAspNetCoreConstants.Properties.Error] = errorCode,
[OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] = errorDescription
});

Loading…
Cancel
Save