/// <summary> /// Facebook on authentication completed callback handler /// </summary> /// <param name="sender">sender of the event</param> /// <param name="e">authentication copmpleted event args</param> protected override async void OnAuthenticationCompletedCallback(object sender, AuthenticatorCompletedEventArgs e) { var response = new AuthenticatedUserResponseEventArgs(false); if (e.IsAuthenticated) { try { // inspect access token and verify permissions were granted var accessToken = e.Account.Properties["access_token"]; // store access token for session management HttpClient client = new HttpClient(); var userProfileReponse = await client.GetStringAsync(UserInfoUrl.Format(accessToken)); var userProfile = JsonConvert.DeserializeObject <FacebookProfile>(userProfileReponse); response.IsAuthenticated = true; response.UserId = userProfile.Id; response.Email = userProfile.Email; response.Name = userProfile.Name; response.ProfileImage = new Xamarin.Forms.Image() { Source = new Uri(userProfile.Picture.Data.Url) }; } catch (Exception) { response.IsAuthenticated = false; } } NotifyOnCompletedEvent(response); }
/// <summary> /// Notifies the on completed event. /// </summary> /// <param name="authenticatedUserResponse">The <see cref="AuthenticatedUserResponseEventArgs"/> instance containing the event data.</param> protected void NotifyOnCompletedEvent(AuthenticatedUserResponseEventArgs authenticatedUserResponse) { _authenticator.Completed -= OnAuthenticationCompletedCallback; OnAuthenticationCompleted?.Invoke(this, authenticatedUserResponse); }