mirror of
https://github.com/bitwarden/android.git
synced 2024-10-31 23:25:45 +03:00
fix error when login token expires
This commit is contained in:
parent
0400d79f43
commit
e1983a7d66
6 changed files with 39 additions and 10 deletions
|
@ -97,7 +97,8 @@ namespace Bit.App
|
||||||
}
|
}
|
||||||
else if(message.Command == "logout")
|
else if(message.Command == "logout")
|
||||||
{
|
{
|
||||||
Device.BeginInvokeOnMainThread(async () => await LogOutAsync(false));
|
Device.BeginInvokeOnMainThread(async () =>
|
||||||
|
await LogOutAsync((message.Data as bool?).GetValueOrDefault()));
|
||||||
}
|
}
|
||||||
else if(message.Command == "loggedOut")
|
else if(message.Command == "loggedOut")
|
||||||
{
|
{
|
||||||
|
@ -240,6 +241,10 @@ namespace Bit.App
|
||||||
_authService.LogOut(() =>
|
_authService.LogOut(() =>
|
||||||
{
|
{
|
||||||
Current.MainPage = new HomePage();
|
Current.MainPage = new HomePage();
|
||||||
|
if(expired)
|
||||||
|
{
|
||||||
|
_platformUtilsService.ShowToast("warning", null, AppResources.LoginExpired);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -456,7 +456,10 @@ namespace Bit.App.Pages
|
||||||
catch(ApiException e)
|
catch(ApiException e)
|
||||||
{
|
{
|
||||||
await _deviceActionService.HideLoadingAsync();
|
await _deviceActionService.HideLoadingAsync();
|
||||||
await Page.DisplayAlert(AppResources.AnErrorHasOccurred, e.Error.GetSingleMessage(), AppResources.Ok);
|
if(e?.Error != null)
|
||||||
|
{
|
||||||
|
await Page.DisplayAlert(AppResources.AnErrorHasOccurred, e.Error.GetSingleMessage(), AppResources.Ok);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
9
src/App/Resources/AppResources.Designer.cs
generated
9
src/App/Resources/AppResources.Designer.cs
generated
|
@ -2274,6 +2274,15 @@ namespace Bit.App.Resources {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Your login session has expired..
|
||||||
|
/// </summary>
|
||||||
|
public static string LoginExpired {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("LoginExpired", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Login.
|
/// Looks up a localized string similar to Login.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -1575,4 +1575,7 @@
|
||||||
<data name="ToggleVisibility" xml:space="preserve">
|
<data name="ToggleVisibility" xml:space="preserve">
|
||||||
<value>Toggle Visibility</value>
|
<value>Toggle Visibility</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="LoginExpired" xml:space="preserve">
|
||||||
|
<value>Your login session has expired.</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
|
@ -23,7 +23,7 @@ namespace Bit.Core.Services
|
||||||
private readonly ICollectionService _collectionService;
|
private readonly ICollectionService _collectionService;
|
||||||
private readonly IStorageService _storageService;
|
private readonly IStorageService _storageService;
|
||||||
private readonly IMessagingService _messagingService;
|
private readonly IMessagingService _messagingService;
|
||||||
private readonly Action _logoutCallback;
|
private readonly Func<bool, Task> _logoutCallbackAsync;
|
||||||
|
|
||||||
public SyncService(
|
public SyncService(
|
||||||
IUserService userService,
|
IUserService userService,
|
||||||
|
@ -35,7 +35,7 @@ namespace Bit.Core.Services
|
||||||
ICollectionService collectionService,
|
ICollectionService collectionService,
|
||||||
IStorageService storageService,
|
IStorageService storageService,
|
||||||
IMessagingService messagingService,
|
IMessagingService messagingService,
|
||||||
Action logoutCallback)
|
Func<bool, Task> logoutCallbackAsync)
|
||||||
{
|
{
|
||||||
_userService = userService;
|
_userService = userService;
|
||||||
_apiService = apiService;
|
_apiService = apiService;
|
||||||
|
@ -46,7 +46,7 @@ namespace Bit.Core.Services
|
||||||
_collectionService = collectionService;
|
_collectionService = collectionService;
|
||||||
_storageService = storageService;
|
_storageService = storageService;
|
||||||
_messagingService = messagingService;
|
_messagingService = messagingService;
|
||||||
_logoutCallback = logoutCallback;
|
_logoutCallbackAsync = logoutCallbackAsync;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool SyncInProgress { get; set; }
|
public bool SyncInProgress { get; set; }
|
||||||
|
@ -307,7 +307,10 @@ namespace Bit.Core.Services
|
||||||
var stamp = await _userService.GetSecurityStampAsync();
|
var stamp = await _userService.GetSecurityStampAsync();
|
||||||
if(stamp != null && stamp != response.SecurityStamp)
|
if(stamp != null && stamp != response.SecurityStamp)
|
||||||
{
|
{
|
||||||
_logoutCallback?.Invoke();
|
if(_logoutCallbackAsync != null)
|
||||||
|
{
|
||||||
|
await _logoutCallbackAsync(true);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await _cryptoService.SetEncKeyAsync(response.Key);
|
await _cryptoService.SetEncKeyAsync(response.Key);
|
||||||
|
|
|
@ -31,8 +31,11 @@ namespace Bit.Core.Utilities
|
||||||
var cryptoFunctionService = new PclCryptoFunctionService(cryptoPrimitiveService);
|
var cryptoFunctionService = new PclCryptoFunctionService(cryptoPrimitiveService);
|
||||||
var cryptoService = new CryptoService(storageService, secureStorageService, cryptoFunctionService);
|
var cryptoService = new CryptoService(storageService, secureStorageService, cryptoFunctionService);
|
||||||
var tokenService = new TokenService(storageService);
|
var tokenService = new TokenService(storageService);
|
||||||
var apiService = new ApiService(tokenService, platformUtilsService, (bool expired) => Task.FromResult(0),
|
var apiService = new ApiService(tokenService, platformUtilsService, (bool expired) =>
|
||||||
customUserAgent);
|
{
|
||||||
|
messagingService.Send("logout", expired);
|
||||||
|
return Task.FromResult(0);
|
||||||
|
}, customUserAgent);
|
||||||
var appIdService = new AppIdService(storageService);
|
var appIdService = new AppIdService(storageService);
|
||||||
var userService = new UserService(storageService, tokenService);
|
var userService = new UserService(storageService, tokenService);
|
||||||
var settingsService = new SettingsService(userService, storageService);
|
var settingsService = new SettingsService(userService, storageService);
|
||||||
|
@ -45,8 +48,11 @@ namespace Bit.Core.Utilities
|
||||||
var lockService = new LockService(cryptoService, userService, platformUtilsService, storageService,
|
var lockService = new LockService(cryptoService, userService, platformUtilsService, storageService,
|
||||||
folderService, cipherService, collectionService, searchService, messagingService, null);
|
folderService, cipherService, collectionService, searchService, messagingService, null);
|
||||||
var syncService = new SyncService(userService, apiService, settingsService, folderService,
|
var syncService = new SyncService(userService, apiService, settingsService, folderService,
|
||||||
cipherService, cryptoService, collectionService, storageService, messagingService,
|
cipherService, cryptoService, collectionService, storageService, messagingService, (bool expired) =>
|
||||||
() => messagingService.Send("logout"));
|
{
|
||||||
|
messagingService.Send("logout", expired);
|
||||||
|
return Task.FromResult(0);
|
||||||
|
});
|
||||||
var passwordGenerationService = new PasswordGenerationService(cryptoService, storageService,
|
var passwordGenerationService = new PasswordGenerationService(cryptoService, storageService,
|
||||||
cryptoFunctionService);
|
cryptoFunctionService);
|
||||||
var totpService = new TotpService(storageService, cryptoFunctionService);
|
var totpService = new TotpService(storageService, cryptoFunctionService);
|
||||||
|
|
Loading…
Reference in a new issue