Skip to content

Commit

Permalink
Add specific error codes for Authentication failures in OpenIddict To…
Browse files Browse the repository at this point in the history
…kenController.Password
  • Loading branch information
alihdev committed Sep 3, 2024
1 parent d9fbfac commit bdc2424
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,13 @@ await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext
});

string errorDescription;
string errorCode;

if (result.IsLockedOut)
{
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.";
errorCode = "account_locked"

Check failure on line 117 in modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.Password.cs

View workflow job for this annotation

GitHub Actions / build-test

; expected

Check failure on line 117 in modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.Password.cs

View workflow job for this annotation

GitHub Actions / build-test

; expected
}
else if (result.IsNotAllowed)
{
Expand All @@ -128,16 +131,18 @@ await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext
}

errorDescription = "You are not allowed to login! Your account is inactive or needs to confirm your email/phone number.";
errorCode = "account_inactive"

Check failure on line 134 in modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.Password.cs

View workflow job for this annotation

GitHub Actions / build-test

; expected

Check failure on line 134 in modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.Password.cs

View workflow job for this annotation

GitHub Actions / build-test

; expected
}
else
{
Logger.LogInformation("Authentication failed for username: {username}, reason: invalid credentials", request.Username);
errorDescription = "Invalid username or password!";
errorCode = OpenIddictConstants.Errors.InvalidGrant

Check failure on line 140 in modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.Password.cs

View workflow job for this annotation

GitHub Actions / build-test

; expected

Check failure on line 140 in modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.Password.cs

View workflow job for this annotation

GitHub Actions / build-test

; expected
}

var properties = new AuthenticationProperties(new Dictionary<string, string>
{
[OpenIddictServerAspNetCoreConstants.Properties.Error] = OpenIddictConstants.Errors.InvalidGrant,
[OpenIddictServerAspNetCoreConstants.Properties.Error] = errorCode,
[OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] = errorDescription
});

Expand Down

0 comments on commit bdc2424

Please sign in to comment.