public Athlete(GoogleUserProfile profile) { Name = profile.Name; Email = profile.Email; AuthenticationId = profile.Id; ProfileImageUrl = profile.Picture; Initialize(); }
/// <summary> /// Registers an athlete with the backend and returns the new athlete profile /// </summary> async Task <Athlete> RegisterAthlete(GoogleUserProfile profile) { AuthenticationStatus = "Registering athlete"; var athlete = new Athlete(profile); await AzureService.Instance.AthleteManager.UpsertAsync(athlete); "You're now an officially registered athlete!".ToToast(); return(athlete); }
async public Task LogOut(bool clearCookies) { await AzureService.Instance.Client.LogoutAsync(); AuthUserProfile = null; Settings.GoogleAccessToken = null; Settings.GoogleRefreshToken = null; Settings.AzureUserId = null; Settings.AzureAuthToken = null; if (clearCookies) { Settings.RegistrationComplete = false; _authenticator.ClearCookies(); } }
/// <summary> /// Attempts to get the user profile from Google. Will use the refresh token if the auth token has expired /// Will set App.CurrentAthlete to the athlete data from Azure /// </summary> async public Task <bool> GetUserProfile() { //Can't get profile w/out a token if (Settings.GoogleAccessToken == null) { return(false); } if (AuthUserProfile != null) { return(true); } AuthenticationStatus = "Getting user profile"; var task = GoogleApiService.Instance.GetUserProfile(Settings.AuthTokenAndType); await RunSafe(task, false); if (task.IsCompleted && task.Result == null) { //Need to refresh the token try { var refreshedUser = await AzureService.Instance.Client.RefreshUserAsync(); await SetIdentityValues(refreshedUser); task = GoogleApiService.Instance.GetUserProfile(Settings.AuthTokenAndType); await RunSafe(task, false); } catch (MobileServiceInvalidOperationException ex) { Debug.WriteLine("Error refreshing token: " + ex); throw; } } if (task.IsCompleted && !task.IsFaulted && task.Result != null) { AuthenticationStatus = "Authentication complete"; AuthUserProfile = task.Result; //InsightsManager.Identify(AuthUserProfile.Email, new Dictionary<string, string> { // { // "Name", // AuthUserProfile.Name // } //}); Settings.GoogleUserId = AuthUserProfile.Id; } else { AuthenticationStatus = "Unable to authenticate"; } if (AuthUserProfile != null && App.Instance.CurrentAthlete == null) { await AuthenticateWithAzure(); } return(AuthUserProfile != null); }