mirror of
https://github.com/bitwarden/server.git
synced 2024-12-24 17:17:40 +01:00
update yubico lib that is netcore compat
This commit is contained in:
parent
c802292098
commit
b5836c524f
@ -59,6 +59,7 @@
|
||||
<PackageReference Include="U2F.Core" Version="1.0.3" />
|
||||
<PackageReference Include="WindowsAzure.Storage" Version="8.1.4" />
|
||||
<PackageReference Include="Otp.NET" Version="1.0.1" />
|
||||
<PackageReference Include="YubicoDotNetClient" Version="1.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
|
||||
@ -66,7 +67,6 @@
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<PackageReference Include="YubicoDotNetClient" Version="1.0.0" />
|
||||
<PackageReference Include="Microsoft.Azure.NotificationHubs" Version="1.0.8" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -2,9 +2,7 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Bit.Core.Models.Table;
|
||||
using Bit.Core.Enums;
|
||||
#if NET461
|
||||
using YubicoDotNetClient;
|
||||
#endif
|
||||
using System.Linq;
|
||||
|
||||
namespace Bit.Core.Identity
|
||||
@ -37,16 +35,16 @@ namespace Bit.Core.Identity
|
||||
return Task.FromResult<string>(null);
|
||||
}
|
||||
|
||||
public Task<bool> ValidateAsync(string purpose, string token, UserManager<User> manager, User user)
|
||||
public async Task<bool> ValidateAsync(string purpose, string token, UserManager<User> manager, User user)
|
||||
{
|
||||
if(!user.Premium)
|
||||
{
|
||||
return Task.FromResult(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(string.IsNullOrWhiteSpace(token) || token.Length != 44)
|
||||
{
|
||||
return Task.FromResult(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
var id = token.Substring(0, 12);
|
||||
@ -54,17 +52,12 @@ namespace Bit.Core.Identity
|
||||
var provider = user.GetTwoFactorProvider(TwoFactorProviderType.YubiKey);
|
||||
if(!provider.MetaData.ContainsValue(id))
|
||||
{
|
||||
return Task.FromResult(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
#if NET461
|
||||
var client = new YubicoClient(_globalSettings.Yubico.ClientId, _globalSettings.Yubico.Key);
|
||||
var response = client.Verify(token);
|
||||
return Task.FromResult(response.Status == YubicoResponseStatus.Ok);
|
||||
#else
|
||||
return Task.FromResult(false);
|
||||
#endif
|
||||
var response = await client.VerifyAsync(token);
|
||||
return response.Status == YubicoResponseStatus.Ok;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user