mirror of
https://github.com/bitwarden/mobile.git
synced 2024-12-30 17:38:11 +01:00
user specific remember two factor
This commit is contained in:
parent
37428c01dd
commit
2f0ca6f7c0
@ -8,7 +8,8 @@ namespace Bit.App.Abstractions
|
|||||||
string RefreshToken { get; set; }
|
string RefreshToken { get; set; }
|
||||||
[Obsolete("Old auth scheme")]
|
[Obsolete("Old auth scheme")]
|
||||||
string AuthBearer { get; set; }
|
string AuthBearer { get; set; }
|
||||||
string TwoFactorToken { get; set; }
|
string GetTwoFactorToken(string email);
|
||||||
|
void SetTwoFactorToken(string email, string token);
|
||||||
DateTime TokenExpiration { get; }
|
DateTime TokenExpiration { get; }
|
||||||
string TokenIssuer { get; }
|
string TokenIssuer { get; }
|
||||||
bool TokenExpired { get; }
|
bool TokenExpired { get; }
|
||||||
|
@ -48,7 +48,7 @@ namespace Bit.App.Repositories
|
|||||||
var errorResponse = JObject.Parse(responseContent);
|
var errorResponse = JObject.Parse(responseContent);
|
||||||
if(errorResponse["TwoFactorProviders2"] != null)
|
if(errorResponse["TwoFactorProviders2"] != null)
|
||||||
{
|
{
|
||||||
TokenService.TwoFactorToken = null;
|
TokenService.SetTwoFactorToken(requestObj.Email, null);
|
||||||
|
|
||||||
return ApiResult<TokenResponse>.Success(new TokenResponse
|
return ApiResult<TokenResponse>.Success(new TokenResponse
|
||||||
{
|
{
|
||||||
|
@ -222,7 +222,7 @@ namespace Bit.App.Services
|
|||||||
Device = new DeviceRequest(_appIdService, _deviceInfoService)
|
Device = new DeviceRequest(_appIdService, _deviceInfoService)
|
||||||
};
|
};
|
||||||
|
|
||||||
var twoFactorToken = _tokenService.TwoFactorToken;
|
var twoFactorToken = _tokenService.GetTwoFactorToken(normalizedEmail);
|
||||||
if(!string.IsNullOrWhiteSpace(twoFactorToken))
|
if(!string.IsNullOrWhiteSpace(twoFactorToken))
|
||||||
{
|
{
|
||||||
request.Token = twoFactorToken;
|
request.Token = twoFactorToken;
|
||||||
@ -281,11 +281,6 @@ namespace Bit.App.Services
|
|||||||
|
|
||||||
private async Task ProcessLoginSuccessAsync(SymmetricCryptoKey key, TokenResponse response)
|
private async Task ProcessLoginSuccessAsync(SymmetricCryptoKey key, TokenResponse response)
|
||||||
{
|
{
|
||||||
if(!string.IsNullOrWhiteSpace(response.TwoFactorToken))
|
|
||||||
{
|
|
||||||
_tokenService.TwoFactorToken = response.TwoFactorToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(response.Key != null)
|
if(response.Key != null)
|
||||||
{
|
{
|
||||||
_cryptoService.SetEncKey(new CipherString(response.Key));
|
_cryptoService.SetEncKey(new CipherString(response.Key));
|
||||||
@ -311,6 +306,11 @@ namespace Bit.App.Services
|
|||||||
_cryptoService.SetOrgKeys(profile.Result);
|
_cryptoService.SetOrgKeys(profile.Result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!string.IsNullOrWhiteSpace(response.TwoFactorToken))
|
||||||
|
{
|
||||||
|
_tokenService.SetTwoFactorToken(_tokenService.TokenEmail, response.TwoFactorToken);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ namespace Bit.App.Services
|
|||||||
{
|
{
|
||||||
private const string TokenKey = "accessToken";
|
private const string TokenKey = "accessToken";
|
||||||
private const string RefreshTokenKey = "refreshToken";
|
private const string RefreshTokenKey = "refreshToken";
|
||||||
private const string TwoFactorTokenKey = "twoFactorToken";
|
private const string TwoFactorTokenKeyFormat = "twoFactorToken_{0}";
|
||||||
private const string AuthBearerKey = "token";
|
private const string AuthBearerKey = "token";
|
||||||
|
|
||||||
private readonly ISecureStorageService _secureStorage;
|
private readonly ISecureStorageService _secureStorage;
|
||||||
@ -166,29 +166,28 @@ namespace Bit.App.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string TwoFactorToken
|
public string GetTwoFactorToken(string email)
|
||||||
{
|
{
|
||||||
get
|
var tokenBytes = _secureStorage.Retrieve(string.Format(TwoFactorTokenKeyFormat, email));
|
||||||
|
if(tokenBytes == null)
|
||||||
{
|
{
|
||||||
var tokenBytes = _secureStorage.Retrieve(TwoFactorTokenKey);
|
return null;
|
||||||
if(tokenBytes == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Encoding.UTF8.GetString(tokenBytes, 0, tokenBytes.Length);
|
|
||||||
}
|
}
|
||||||
set
|
|
||||||
|
return Encoding.UTF8.GetString(tokenBytes, 0, tokenBytes.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetTwoFactorToken(string email, string token)
|
||||||
|
{
|
||||||
|
var key = string.Format(TwoFactorTokenKeyFormat, email);
|
||||||
|
if(token != null)
|
||||||
{
|
{
|
||||||
if(value != null)
|
var tokenBytes = Encoding.UTF8.GetBytes(token);
|
||||||
{
|
_secureStorage.Store(key, tokenBytes);
|
||||||
var tokenBytes = Encoding.UTF8.GetBytes(value);
|
}
|
||||||
_secureStorage.Store(TwoFactorTokenKey, tokenBytes);
|
else
|
||||||
}
|
{
|
||||||
else
|
_secureStorage.Delete(key);
|
||||||
{
|
|
||||||
_secureStorage.Delete(TwoFactorTokenKey);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user