public static async Task RefreshLoginAsync() { if (!string.IsNullOrEmpty(UserSettings.AuthToken)) { try { DependencyService.Get <IMetricsManagerService>().TrackEvent("UserRefresh"); Authenticator.User = new MobileServiceUser(UserSettings.UserId) { MobileServiceAuthenticationToken = UserSettings.AuthToken, }; var user = await Authenticator.RefreshLoginAsync(); Authenticator.User = user; UserSettings.Volunteer = await SurveyCloudService.GetVolunteerAsync(); UserSettings.AuthToken = user?.MobileServiceAuthenticationToken; UserSettings.UserId = user?.UserId; } catch (Exception ex) { DependencyService.Get <IMetricsManagerService>().TrackException("UserRefreshFailed", ex); Authenticator.User = null; UserSettings.Volunteer = new VolunteerModel(); UserSettings.VolunteerId = null; UserSettings.AuthToken = null; UserSettings.UserId = null; } } else { try { DependencyService.Get <IMetricsManagerService>().TrackEvent("GetAnonymousVolunteer"); UserSettings.Volunteer = await SurveyCloudService.GetVolunteerAsync(); } catch (Exception ex) { DependencyService.Get <IMetricsManagerService>().TrackException("GetAnonymousVolunteerFailed", ex); } } }
public static async Task LoginAsync(MobileServiceAuthenticationProvider provider) { try { DependencyService.Get <IMetricsManagerService>().TrackEvent("UserLogin"); var properties = provider == MobileServiceAuthenticationProvider.Google ? new Dictionary <string, string> { { "access_type", "offline" }, } : new Dictionary <string, string>(0); var user = await Authenticator.LoginAsync(provider, properties); UserSettings.Volunteer = await SurveyCloudService.GetVolunteerAsync(); UserSettings.AuthToken = user?.MobileServiceAuthenticationToken; UserSettings.UserId = user?.UserId; } catch (Exception ex) { DependencyService.Get <IMetricsManagerService>().TrackException("UserLoginFailed", ex); } }