Skip to content

Commit 6d81e93

Browse files
committed
Add specific error codes for Authentication failures in OpenIddict TokenController.Password
1 parent d9fbfac commit 6d81e93

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,13 @@ await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext
108108
});
109109

110110
string errorDescription;
111+
string errorCode;
112+
111113
if (result.IsLockedOut)
112114
{
113115
Logger.LogInformation("Authentication failed for username: {username}, reason: locked out", request.Username);
114116
errorDescription = "The user account has been locked out due to invalid login attempts. Please wait a while and try again.";
117+
errorCode = "account_locked";
115118
}
116119
else if (result.IsNotAllowed)
117120
{
@@ -128,16 +131,18 @@ await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext
128131
}
129132

130133
errorDescription = "You are not allowed to login! Your account is inactive or needs to confirm your email/phone number.";
134+
errorCode = "account_inactive";
131135
}
132136
else
133137
{
134138
Logger.LogInformation("Authentication failed for username: {username}, reason: invalid credentials", request.Username);
135139
errorDescription = "Invalid username or password!";
140+
errorCode = OpenIddictConstants.Errors.InvalidGrant;
136141
}
137142

138143
var properties = new AuthenticationProperties(new Dictionary<string, string>
139144
{
140-
[OpenIddictServerAspNetCoreConstants.Properties.Error] = OpenIddictConstants.Errors.InvalidGrant,
145+
[OpenIddictServerAspNetCoreConstants.Properties.Error] = errorCode,
141146
[OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] = errorDescription
142147
});
143148

0 commit comments

Comments
 (0)