public async Task VerifyTokenAsync() { StoreSettings settings = await ReadSettingsAsync(); if (settings != null) { try { if (!string.IsNullOrEmpty(settings.AuthToken) && JwtUtility.GetTokenExpiration(settings.AuthToken) < DateTime.UtcNow) { if (CrossConnectivity.Current.IsConnected) { var result = await RegenerateTokenAsync(); if (!result) { //no token regenerated await LogoutAsync(); } } } } catch (InvalidTokenException) { //Token exception error if (CrossConnectivity.Current.IsConnected) { await LogoutAsync(); } } } }
async Task LoadCachedTokenAsync() { StoreSettings settings = await ReadSettingsAsync(); if (settings != null) { try { if (!string.IsNullOrEmpty(settings.AuthToken) && JwtUtility.GetTokenExpiration(settings.AuthToken) > DateTime.UtcNow) { MobileService.CurrentUser = new MobileServiceUser(settings.UserId); MobileService.CurrentUser.MobileServiceAuthenticationToken = settings.AuthToken; } } catch (InvalidTokenException) { settings.AuthToken = string.Empty; settings.UserId = string.Empty; await SaveSettingsAsync(settings); } } }