diff --git a/src/Api/settings.json b/src/Api/settings.json index 642be3b400..7822808cdc 100644 --- a/src/Api/settings.json +++ b/src/Api/settings.json @@ -34,6 +34,10 @@ "notificationHub": { "connectionString": "SECRET", "hubName": "SECRET" + }, + "yubico": { + "clientid": "SECRET", + "key": "SECRET" } }, "IpRateLimitOptions": { diff --git a/src/Core/GlobalSettings.cs b/src/Core/GlobalSettings.cs index 35aa1aded5..ab77ace8f2 100644 --- a/src/Core/GlobalSettings.cs +++ b/src/Core/GlobalSettings.cs @@ -14,6 +14,7 @@ public virtual DataProtectionSettings DataProtection { get; set; } = new DataProtectionSettings(); public virtual DocumentDbSettings DocumentDb { get; set; } = new DocumentDbSettings(); public virtual NotificationHubSettings NotificationHub { get; set; } = new NotificationHubSettings(); + public virtual YubicoSettings Yubico { get; set; } = new YubicoSettings(); public class SqlServerSettings { @@ -71,5 +72,11 @@ public string ConnectionString { get; set; } public string HubName { get; set; } } + + public class YubicoSettings + { + public string ClientId { get; set; } + public string Key { get; set; } + } } } diff --git a/src/Core/Identity/YubicoOtpTokenProvider.cs b/src/Core/Identity/YubicoOtpTokenProvider.cs index be808f0262..f7fb1601fe 100644 --- a/src/Core/Identity/YubicoOtpTokenProvider.cs +++ b/src/Core/Identity/YubicoOtpTokenProvider.cs @@ -9,6 +9,13 @@ namespace Bit.Core.Identity { public class YubicoOtpTokenProvider : IUserTwoFactorTokenProvider { + private readonly GlobalSettings _globalSettings; + + public YubicoOtpTokenProvider(GlobalSettings globalSettings) + { + _globalSettings = globalSettings; + } + public Task CanGenerateTwoFactorTokenAsync(UserManager manager, User user) { var provider = user.GetTwoFactorProvider(TwoFactorProviderType.YubiKey); @@ -41,7 +48,7 @@ namespace Bit.Core.Identity return Task.FromResult(false); } - var client = new YubicoClient("TODO", "TODO"); + var client = new YubicoClient(_globalSettings.Yubico.ClientId, _globalSettings.Yubico.ClientId); var response = client.Verify(token); return Task.FromResult(response.Status == YubicoResponseStatus.Ok); } diff --git a/src/Core/Utilities/ServiceCollectionExtensions.cs b/src/Core/Utilities/ServiceCollectionExtensions.cs index bcf6dfae72..2422b1bcd4 100644 --- a/src/Core/Utilities/ServiceCollectionExtensions.cs +++ b/src/Core/Utilities/ServiceCollectionExtensions.cs @@ -96,6 +96,8 @@ namespace Bit.Core.Utilities .AddUserStore() .AddRoleStore() .AddTokenProvider(TwoFactorProviderType.Authenticator.ToString()) + .AddTokenProvider(TwoFactorProviderType.YubiKey.ToString()) + .AddTokenProvider(TwoFactorProviderType.Duo.ToString()) .AddTokenProvider>(TokenOptions.DefaultEmailProvider); return identityBuilder;