Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Specific Error Codes for Authentication Failures #20716

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";
}
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";
}
else
{
Logger.LogInformation("Authentication failed for username: {username}, reason: invalid credentials", request.Username);
errorDescription = "Invalid username or password!";
errorCode = OpenIddictConstants.Errors.InvalidGrant;
}

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

Expand Down
Loading