mirror of
https://github.com/bitwarden/server.git
synced 2024-12-28 17:57:37 +01:00
token providers cant inject userservice
This commit is contained in:
parent
cf73b168ee
commit
db3316dd60
@ -5,16 +5,17 @@ using Bit.Core.Models.Table;
|
|||||||
using Bit.Core.Enums;
|
using Bit.Core.Enums;
|
||||||
using OtpNet;
|
using OtpNet;
|
||||||
using Bit.Core.Services;
|
using Bit.Core.Services;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace Bit.Core.Identity
|
namespace Bit.Core.Identity
|
||||||
{
|
{
|
||||||
public class AuthenticatorTokenProvider : IUserTwoFactorTokenProvider<User>
|
public class AuthenticatorTokenProvider : IUserTwoFactorTokenProvider<User>
|
||||||
{
|
{
|
||||||
private readonly IUserService _userService;
|
private readonly IServiceProvider _serviceProvider;
|
||||||
|
|
||||||
public AuthenticatorTokenProvider(IUserService userService)
|
public AuthenticatorTokenProvider(IServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
_userService = userService;
|
_serviceProvider = serviceProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> CanGenerateTwoFactorTokenAsync(UserManager<User> manager, User user)
|
public async Task<bool> CanGenerateTwoFactorTokenAsync(UserManager<User> manager, User user)
|
||||||
@ -24,7 +25,8 @@ namespace Bit.Core.Identity
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return await user.TwoFactorProviderIsEnabledAsync(TwoFactorProviderType.Authenticator, _userService);
|
return await user.TwoFactorProviderIsEnabledAsync(TwoFactorProviderType.Authenticator,
|
||||||
|
_serviceProvider.GetRequiredService<IUserService>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<string> GenerateAsync(string purpose, UserManager<User> manager, User user)
|
public Task<string> GenerateAsync(string purpose, UserManager<User> manager, User user)
|
||||||
|
@ -4,26 +4,29 @@ using Bit.Core.Models.Table;
|
|||||||
using Bit.Core.Enums;
|
using Bit.Core.Enums;
|
||||||
using Bit.Core.Utilities.Duo;
|
using Bit.Core.Utilities.Duo;
|
||||||
using Bit.Core.Models;
|
using Bit.Core.Models;
|
||||||
|
using System;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Bit.Core.Services;
|
using Bit.Core.Services;
|
||||||
|
|
||||||
namespace Bit.Core.Identity
|
namespace Bit.Core.Identity
|
||||||
{
|
{
|
||||||
public class DuoWebTokenProvider : IUserTwoFactorTokenProvider<User>
|
public class DuoWebTokenProvider : IUserTwoFactorTokenProvider<User>
|
||||||
{
|
{
|
||||||
private readonly IUserService _userService;
|
private readonly IServiceProvider _serviceProvider;
|
||||||
private readonly GlobalSettings _globalSettings;
|
private readonly GlobalSettings _globalSettings;
|
||||||
|
|
||||||
public DuoWebTokenProvider(
|
public DuoWebTokenProvider(
|
||||||
IUserService userService,
|
IServiceProvider serviceProvider,
|
||||||
GlobalSettings globalSettings)
|
GlobalSettings globalSettings)
|
||||||
{
|
{
|
||||||
_userService = userService;
|
_serviceProvider = serviceProvider;
|
||||||
_globalSettings = globalSettings;
|
_globalSettings = globalSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> CanGenerateTwoFactorTokenAsync(UserManager<User> manager, User user)
|
public async Task<bool> CanGenerateTwoFactorTokenAsync(UserManager<User> manager, User user)
|
||||||
{
|
{
|
||||||
if(!(await _userService.CanAccessPremium(user)))
|
var userService = _serviceProvider.GetRequiredService<IUserService>();
|
||||||
|
if(!(await userService.CanAccessPremium(user)))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -34,12 +37,13 @@ namespace Bit.Core.Identity
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return await user.TwoFactorProviderIsEnabledAsync(TwoFactorProviderType.Duo, _userService);
|
return await user.TwoFactorProviderIsEnabledAsync(TwoFactorProviderType.Duo, userService);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> GenerateAsync(string purpose, UserManager<User> manager, User user)
|
public async Task<string> GenerateAsync(string purpose, UserManager<User> manager, User user)
|
||||||
{
|
{
|
||||||
if(!(await _userService.CanAccessPremium(user)))
|
var userService = _serviceProvider.GetRequiredService<IUserService>();
|
||||||
|
if(!(await userService.CanAccessPremium(user)))
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -57,7 +61,8 @@ namespace Bit.Core.Identity
|
|||||||
|
|
||||||
public async 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(!(await _userService.CanAccessPremium(user)))
|
var userService = _serviceProvider.GetRequiredService<IUserService>();
|
||||||
|
if(!(await userService.CanAccessPremium(user)))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -12,28 +12,30 @@ using U2F.Core.Models;
|
|||||||
using U2F.Core.Exceptions;
|
using U2F.Core.Exceptions;
|
||||||
using System;
|
using System;
|
||||||
using Bit.Core.Services;
|
using Bit.Core.Services;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace Bit.Core.Identity
|
namespace Bit.Core.Identity
|
||||||
{
|
{
|
||||||
public class U2fTokenProvider : IUserTwoFactorTokenProvider<User>
|
public class U2fTokenProvider : IUserTwoFactorTokenProvider<User>
|
||||||
{
|
{
|
||||||
private readonly IUserService _userService;
|
private readonly IServiceProvider _serviceProvider;
|
||||||
private readonly IU2fRepository _u2fRepository;
|
private readonly IU2fRepository _u2fRepository;
|
||||||
private readonly GlobalSettings _globalSettings;
|
private readonly GlobalSettings _globalSettings;
|
||||||
|
|
||||||
public U2fTokenProvider(
|
public U2fTokenProvider(
|
||||||
IUserService userService,
|
IServiceProvider serviceProvider,
|
||||||
IU2fRepository u2fRepository,
|
IU2fRepository u2fRepository,
|
||||||
GlobalSettings globalSettings)
|
GlobalSettings globalSettings)
|
||||||
{
|
{
|
||||||
_userService = userService;
|
_serviceProvider = serviceProvider;
|
||||||
_u2fRepository = u2fRepository;
|
_u2fRepository = u2fRepository;
|
||||||
_globalSettings = globalSettings;
|
_globalSettings = globalSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> CanGenerateTwoFactorTokenAsync(UserManager<User> manager, User user)
|
public async Task<bool> CanGenerateTwoFactorTokenAsync(UserManager<User> manager, User user)
|
||||||
{
|
{
|
||||||
if(!(await _userService.CanAccessPremium(user)))
|
var userService = _serviceProvider.GetRequiredService<IUserService>();
|
||||||
|
if(!(await userService.CanAccessPremium(user)))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -44,12 +46,13 @@ namespace Bit.Core.Identity
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return await user.TwoFactorProviderIsEnabledAsync(TwoFactorProviderType.U2f, _userService);
|
return await user.TwoFactorProviderIsEnabledAsync(TwoFactorProviderType.U2f, userService);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> GenerateAsync(string purpose, UserManager<User> manager, User user)
|
public async Task<string> GenerateAsync(string purpose, UserManager<User> manager, User user)
|
||||||
{
|
{
|
||||||
if(!(await _userService.CanAccessPremium(user)))
|
var userService = _serviceProvider.GetRequiredService<IUserService>();
|
||||||
|
if(!(await userService.CanAccessPremium(user)))
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -108,7 +111,8 @@ namespace Bit.Core.Identity
|
|||||||
|
|
||||||
public async 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(!(await _userService.CanAccessPremium(user)) || string.IsNullOrWhiteSpace(token))
|
var userService = _serviceProvider.GetRequiredService<IUserService>();
|
||||||
|
if(!(await userService.CanAccessPremium(user)) || string.IsNullOrWhiteSpace(token))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -5,25 +5,28 @@ using Bit.Core.Enums;
|
|||||||
using YubicoDotNetClient;
|
using YubicoDotNetClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Bit.Core.Services;
|
using Bit.Core.Services;
|
||||||
|
using System;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace Bit.Core.Identity
|
namespace Bit.Core.Identity
|
||||||
{
|
{
|
||||||
public class YubicoOtpTokenProvider : IUserTwoFactorTokenProvider<User>
|
public class YubicoOtpTokenProvider : IUserTwoFactorTokenProvider<User>
|
||||||
{
|
{
|
||||||
private readonly IUserService _userService;
|
private readonly IServiceProvider _serviceProvider;
|
||||||
private readonly GlobalSettings _globalSettings;
|
private readonly GlobalSettings _globalSettings;
|
||||||
|
|
||||||
public YubicoOtpTokenProvider(
|
public YubicoOtpTokenProvider(
|
||||||
IUserService userService,
|
IServiceProvider serviceProvider,
|
||||||
GlobalSettings globalSettings)
|
GlobalSettings globalSettings)
|
||||||
{
|
{
|
||||||
_userService = userService;
|
_serviceProvider = serviceProvider;
|
||||||
_globalSettings = globalSettings;
|
_globalSettings = globalSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> CanGenerateTwoFactorTokenAsync(UserManager<User> manager, User user)
|
public async Task<bool> CanGenerateTwoFactorTokenAsync(UserManager<User> manager, User user)
|
||||||
{
|
{
|
||||||
if(!(await _userService.CanAccessPremium(user)))
|
var userService = _serviceProvider.GetRequiredService<IUserService>();
|
||||||
|
if(!(await userService.CanAccessPremium(user)))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -34,7 +37,7 @@ namespace Bit.Core.Identity
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return await user.TwoFactorProviderIsEnabledAsync(TwoFactorProviderType.YubiKey, _userService);
|
return await user.TwoFactorProviderIsEnabledAsync(TwoFactorProviderType.YubiKey, userService);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<string> GenerateAsync(string purpose, UserManager<User> manager, User user)
|
public Task<string> GenerateAsync(string purpose, UserManager<User> manager, User user)
|
||||||
@ -44,7 +47,8 @@ namespace Bit.Core.Identity
|
|||||||
|
|
||||||
public async 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(!(await _userService.CanAccessPremium(user)))
|
var userService = _serviceProvider.GetRequiredService<IUserService>();
|
||||||
|
if(!(await userService.CanAccessPremium(user)))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user