mirror of
https://github.com/bitwarden/server.git
synced 2025-05-20 02:54:32 -05:00
Added support for device registration during two factor login
This commit is contained in:
parent
452d74a266
commit
d300c82ffd
@ -45,7 +45,7 @@ namespace Bit.Api.Controllers
|
||||
[Authorize("TwoFactor")]
|
||||
public async Task<AuthTokenResponseModel> PostTokenTwoFactor([FromBody]AuthTokenTwoFactorRequestModel model)
|
||||
{
|
||||
var result = await _signInManager.TwoFactorSignInAsync(_currentContext.User, model.Provider, model.Code);
|
||||
var result = await _signInManager.TwoFactorSignInAsync(_currentContext.User, model.Provider, model.Code, model.Device?.ToDevice());
|
||||
if(result == JwtBearerSignInResult.Success)
|
||||
{
|
||||
return new AuthTokenResponseModel(result.Token, result.User);
|
||||
|
@ -8,5 +8,6 @@ namespace Bit.Api.Models
|
||||
public string Code { get; set; }
|
||||
[Required]
|
||||
public string Provider { get; set; }
|
||||
public DeviceRequestModel Device { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ namespace Bit.Core.Identity
|
||||
return await PasswordSignInAsync(user, password, device);
|
||||
}
|
||||
|
||||
public async Task<JwtBearerSignInResult> TwoFactorSignInAsync(User user, string provider, string code)
|
||||
public async Task<JwtBearerSignInResult> TwoFactorSignInAsync(User user, string provider, string code, Device device = null)
|
||||
{
|
||||
if(user == null)
|
||||
{
|
||||
@ -111,6 +111,13 @@ namespace Bit.Core.Identity
|
||||
success.Token = token;
|
||||
success.User = user;
|
||||
|
||||
var existingDevice = await _deviceRepository.GetByIdentifierAsync(device.Identifier, user.Id);
|
||||
if(existingDevice == null)
|
||||
{
|
||||
device.UserId = user.Id;
|
||||
await _deviceRepository.CreateAsync(device);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user