remeber two factor token

This commit is contained in:
Kyle Spearrin 2017-06-27 16:35:29 -04:00
parent 4116d95a3e
commit 37428c01dd
6 changed files with 46 additions and 1 deletions

View file

@ -8,6 +8,7 @@ namespace Bit.App.Abstractions
string RefreshToken { get; set; }
[Obsolete("Old auth scheme")]
string AuthBearer { get; set; }
string TwoFactorToken { get; set; }
DateTime TokenExpiration { get; }
string TokenIssuer { get; }
bool TokenExpired { get; }

View file

@ -16,6 +16,7 @@ namespace Bit.App.Models.Api
public string TokenType { get; set; }
public Dictionary<TwoFactorProviderType, Dictionary<string, object>> TwoFactorProviders2 { get; set; }
public string PrivateKey { get; set; }
public string TwoFactorToken { get; set; }
public string Key { get; set; }
}
}

View file

@ -189,6 +189,8 @@ namespace Bit.App.Pages
return;
}
PasswordCell.Entry.Text = string.Empty;
if(result.TwoFactorRequired)
{
_googleAnalyticsService.TrackAppEvent("LoggedIn To Two-step");

View file

@ -5,7 +5,6 @@ using Bit.App.Abstractions;
using Bit.App.Models.Api;
using Newtonsoft.Json;
using Plugin.Connectivity.Abstractions;
using System.Net;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using Bit.App.Enums;
@ -49,6 +48,8 @@ namespace Bit.App.Repositories
var errorResponse = JObject.Parse(responseContent);
if(errorResponse["TwoFactorProviders2"] != null)
{
TokenService.TwoFactorToken = null;
return ApiResult<TokenResponse>.Success(new TokenResponse
{
TwoFactorProviders2 =

View file

@ -222,6 +222,14 @@ namespace Bit.App.Services
Device = new DeviceRequest(_appIdService, _deviceInfoService)
};
var twoFactorToken = _tokenService.TwoFactorToken;
if(!string.IsNullOrWhiteSpace(twoFactorToken))
{
request.Token = twoFactorToken;
request.Provider = TwoFactorProviderType.Remember;
request.Remember = false;
}
var response = await _connectApiRepository.PostTokenAsync(request);
if(!response.Succeeded)
{
@ -273,6 +281,11 @@ namespace Bit.App.Services
private async Task ProcessLoginSuccessAsync(SymmetricCryptoKey key, TokenResponse response)
{
if(!string.IsNullOrWhiteSpace(response.TwoFactorToken))
{
_tokenService.TwoFactorToken = response.TwoFactorToken;
}
if(response.Key != null)
{
_cryptoService.SetEncKey(new CipherString(response.Key));

View file

@ -9,6 +9,7 @@ namespace Bit.App.Services
{
private const string TokenKey = "accessToken";
private const string RefreshTokenKey = "refreshToken";
private const string TwoFactorTokenKey = "twoFactorToken";
private const string AuthBearerKey = "token";
private readonly ISecureStorageService _secureStorage;
@ -165,6 +166,32 @@ namespace Bit.App.Services
}
}
public string TwoFactorToken
{
get
{
var tokenBytes = _secureStorage.Retrieve(TwoFactorTokenKey);
if(tokenBytes == null)
{
return null;
}
return Encoding.UTF8.GetString(tokenBytes, 0, tokenBytes.Length);
}
set
{
if(value != null)
{
var tokenBytes = Encoding.UTF8.GetBytes(value);
_secureStorage.Store(TwoFactorTokenKey, tokenBytes);
}
else
{
_secureStorage.Delete(TwoFactorTokenKey);
}
}
}
public JObject DecodeToken()
{
if(_decodedToken != null)