protected void AddToken(HttpClient client) { if (string.IsNullOrEmpty(_Configuration.AuthToken)) { return; } // get the token from storage string token = _StorageService.Get <string>(_Configuration.AuthToken); if (!string.IsNullOrEmpty(token)) { // reset token validity - only once // this allows the app to die nicely if not in use for double the token validity period if (!_IsRefreshing) { Task.Run(() => RefreshTokenAsync()); } // get token from settings service if (client.DefaultRequestHeaders.Contains(_Configuration.AuthToken)) { client.DefaultRequestHeaders.Remove(_Configuration.AuthToken); } // ensure that we always use the most up to date token client.DefaultRequestHeaders.Add(_Configuration.AuthToken, token); } client.Timeout = new TimeSpan(0, 0, _Timeout); }
private async Task AddToken(HttpClient client) { // get the token from storage string token = _LocalStorage.Get <string>(_Configuration.AuthToken); if (!string.IsNullOrEmpty(token)) { // get token from settings service if (client.DefaultRequestHeaders.ContainsKey(_Configuration.AuthToken)) { client.DefaultRequestHeaders.Remove(_Configuration.AuthToken); } // ensure that we always use the most up to date token client.DefaultRequestHeaders.Add(_Configuration.AuthToken, token); } }
public ServiceResult <User> InitLastUser() { System.Diagnostics.Debug.WriteLine($"*** {GetType().Name}.{nameof(InitLastUser)} - Try to get the last user..."); try { User = _LocalStorageService.Get <User>(CURRENT_USER_KEY, true); UserChanged?.Invoke(this, new EventArgs()); return(new ServiceResult <User> { Status = ServiceResultStatus.Success, Payload = User }); } catch (Exception ex) { return(new ServiceResult <User> { Status = ServiceResultStatus.Error }); } }
/// <summary> /// Ctor /// </summary> public SettingsMenuPage() { InitializeComponent(); securityService = DependencyService.Get <ISecurityService>(); localStorageService = DependencyService.Get <ILocalStorageService>(); birthdayEventService = DependencyService.Get <IBirthdayEventService>(); settings = localStorageService.Get <GlobalSettings>(typeof(GlobalSettings).Name); if (settings == null) { settings = new GlobalSettings() { Host = "localhost", Login = "******" }; } CheckConnection(); }