1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-23 17:07:42 +01:00

update yubico lib that is netcore compat

This commit is contained in:
Kyle Spearrin 2017-08-10 09:49:50 -04:00
parent c802292098
commit b5836c524f
2 changed files with 7 additions and 14 deletions

View File

@ -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>

View File

@ -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;
}
}
}