mirror of
https://github.com/bitwarden/server.git
synced 2024-11-25 12:45:18 +01:00
Parse enum as to accept 0 values or full string values
This commit is contained in:
parent
4354006a27
commit
8514d1f16d
@ -210,7 +210,7 @@ namespace Bit.Api.Controllers
|
||||
throw new BadRequestException("MasterPasswordHash", "Invalid password.");
|
||||
}
|
||||
|
||||
if(!await _userManager.VerifyTwoFactorTokenAsync(user, "Authenticator", model.Token))
|
||||
if(!await _userManager.VerifyTwoFactorTokenAsync(user, TwoFactorProviderType.Authenticator.ToString(), model.Token))
|
||||
{
|
||||
await Task.Delay(2000);
|
||||
throw new BadRequestException("Token", "Invalid token.");
|
||||
@ -247,7 +247,7 @@ namespace Bit.Api.Controllers
|
||||
throw new BadRequestException("MasterPasswordHash", "Invalid password.");
|
||||
}
|
||||
|
||||
if(!await _userManager.VerifyTwoFactorTokenAsync(user, "Authenticator", model.Token))
|
||||
if(!await _userManager.VerifyTwoFactorTokenAsync(user, TwoFactorProviderType.Authenticator.ToString(), model.Token))
|
||||
{
|
||||
await Task.Delay(2000);
|
||||
throw new BadRequestException("Token", "Invalid token.");
|
||||
|
@ -76,14 +76,21 @@ namespace Bit.Api.IdentityServer
|
||||
{
|
||||
if(await _userManager.CheckPasswordAsync(user, context.Password))
|
||||
{
|
||||
TwoFactorProviderType twoFactorProviderType = TwoFactorProviderType.Authenticator; // Just defaulting it
|
||||
if(!twoFactorRequest && await TwoFactorRequiredAsync(user))
|
||||
{
|
||||
BuildTwoFactorResult(user, context);
|
||||
return;
|
||||
}
|
||||
|
||||
if(twoFactorRequest && !Enum.TryParse(twoFactorProvider, out twoFactorProviderType))
|
||||
{
|
||||
BuildTwoFactorResult(user, context);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!twoFactorRequest ||
|
||||
await _userManager.VerifyTwoFactorTokenAsync(user, twoFactorProvider, twoFactorToken))
|
||||
await _userManager.VerifyTwoFactorTokenAsync(user, twoFactorProviderType.ToString(), twoFactorToken))
|
||||
{
|
||||
var device = await SaveDeviceAsync(user, context);
|
||||
BuildSuccessResult(user, context, device);
|
||||
|
@ -30,6 +30,7 @@ using Bit.Core.Utilities;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
using Bit.Api.IdentityServer;
|
||||
using Bit.Core.Enums;
|
||||
|
||||
namespace Bit.Api
|
||||
{
|
||||
@ -150,7 +151,7 @@ namespace Bit.Api
|
||||
})
|
||||
.AddUserStore<UserStore>()
|
||||
.AddRoleStore<RoleStore>()
|
||||
.AddTokenProvider<AuthenticatorTokenProvider>("Authenticator")
|
||||
.AddTokenProvider<AuthenticatorTokenProvider>(TwoFactorProviderType.Authenticator.ToString())
|
||||
.AddTokenProvider<EmailTokenProvider<User>>(TokenOptions.DefaultEmailProvider);
|
||||
|
||||
var jwtIdentityOptions = provider.GetRequiredService<IOptions<JwtBearerIdentityOptions>>().Value;
|
||||
|
@ -273,13 +273,13 @@ namespace Bit.Core.Services
|
||||
return IdentityResult.Failed(_identityErrorDescriber.PasswordMismatch());
|
||||
}
|
||||
|
||||
public async Task GetTwoFactorAsync(User user, Enums.TwoFactorProviderType provider)
|
||||
public async Task GetTwoFactorAsync(User user, TwoFactorProviderType provider)
|
||||
{
|
||||
if(user.TwoFactorEnabled && user.TwoFactorProvider.HasValue && user.TwoFactorProvider.Value == provider)
|
||||
{
|
||||
switch(provider)
|
||||
{
|
||||
case Enums.TwoFactorProviderType.Authenticator:
|
||||
case TwoFactorProviderType.Authenticator:
|
||||
if(!string.IsNullOrWhiteSpace(user.AuthenticatorKey))
|
||||
{
|
||||
return;
|
||||
@ -296,7 +296,7 @@ namespace Bit.Core.Services
|
||||
|
||||
switch(provider)
|
||||
{
|
||||
case Enums.TwoFactorProviderType.Authenticator:
|
||||
case TwoFactorProviderType.Authenticator:
|
||||
var key = KeyGeneration.GenerateRandomKey(20);
|
||||
user.AuthenticatorKey = Base32Encoding.ToString(key);
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user