mirror of
https://github.com/streetwriters/notesnook-sync-server.git
synced 2026-02-12 19:22:45 +00:00
identity: many fixes to auth grant validation
This commit is contained in:
@@ -26,11 +26,12 @@ namespace Streetwriters.Identity.Validation
|
||||
{
|
||||
public LockedOutValidationResult(TimeSpan? timeLeft)
|
||||
{
|
||||
base.Error = "locked_out";
|
||||
Error = "locked_out";
|
||||
IsError = true;
|
||||
if (timeLeft.HasValue)
|
||||
base.ErrorDescription = $"You have been locked out. Please try again in {timeLeft?.Minutes.Pluralize("minute", "minutes")} and {timeLeft?.Seconds.Pluralize("second", "seconds")}.";
|
||||
ErrorDescription = $"You have been locked out. Please try again in {timeLeft?.Minutes.Pluralize("minute", "minutes")} and {timeLeft?.Seconds.Pluralize("second", "seconds")}.";
|
||||
else
|
||||
base.ErrorDescription = $"You have been locked out.";
|
||||
ErrorDescription = $"You have been locked out.";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,6 +89,14 @@ namespace Streetwriters.Identity.Validation
|
||||
var user = await UserManager.FindByIdAsync(userId);
|
||||
if (user == null) return;
|
||||
|
||||
var isLockedOut = await UserManager.IsLockedOutAsync(user);
|
||||
if (isLockedOut)
|
||||
{
|
||||
var timeLeft = user.LockoutEnd - DateTimeOffset.Now;
|
||||
context.Result = new LockedOutValidationResult(timeLeft);
|
||||
return;
|
||||
}
|
||||
|
||||
context.Result.Error = "invalid_mfa";
|
||||
context.Result.ErrorDescription = "Please provide a valid multi-factor authentication code.";
|
||||
|
||||
@@ -102,14 +110,6 @@ namespace Streetwriters.Identity.Validation
|
||||
return;
|
||||
}
|
||||
|
||||
var isLockedOut = await UserManager.IsLockedOutAsync(user);
|
||||
if (isLockedOut)
|
||||
{
|
||||
var timeLeft = user.LockoutEnd - DateTimeOffset.Now;
|
||||
context.Result = new LockedOutValidationResult(timeLeft);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mfaMethod == MFAMethods.RecoveryCode)
|
||||
{
|
||||
context.Result.ErrorDescription = "Please provide a valid multi-factor authentication recovery code.";
|
||||
@@ -132,8 +132,9 @@ namespace Streetwriters.Identity.Validation
|
||||
}
|
||||
}
|
||||
|
||||
await UserManager.ResetAccessFailedCountAsync(user);
|
||||
context.Result.IsError = false;
|
||||
context.Result.Subject = await TokenGenerationService.TransformTokenRequestAsync(context.Request, user, GrantType, new string[] { Config.MFA_PASSWORD_GRANT_TYPE_SCOPE });
|
||||
context.Result.Subject = await TokenGenerationService.TransformTokenRequestAsync(context.Request, user, GrantType, [Config.MFA_PASSWORD_GRANT_TYPE_SCOPE]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -101,6 +101,7 @@ namespace Streetwriters.Identity.Validation
|
||||
return;
|
||||
}
|
||||
|
||||
await UserManager.ResetAccessFailedCountAsync(user);
|
||||
var sub = await UserManager.GetUserIdAsync(user);
|
||||
context.Result = new GrantValidationResult(sub, AuthenticationMethods.Password);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user