public override void DidSignIn(SignIn signIn, Google.SignIn.GoogleUser user, NSError error)
        {
            if (error != null)
            {
                OnError?.Invoke(this, new Error()
                {
                    Message = error.LocalizedDescription
                });
                return;
            }


            var authCode = user.ServerAuthCode;

            if (!string.IsNullOrEmpty(authCode))
            {
                OnAuthCodeReceived?.Invoke(this, authCode);
            }
            else
            {
                OnLogin?.Invoke(this, new Data.GoogleUser()
                {
                    Id              = user.UserId,
                    DisplayName     = user.Profile.Name,
                    IdToken         = user.Authentication.IdToken,
                    Base            = user,
                    AuthCode        = user.ServerAuthCode,
                    Email           = user.Profile.Email,
                    FamilyName      = user.Profile.Email,
                    GivenName       = user.Profile.GivenName,
                    GrantedScopes   = user.GrantedScopes.ToArray(),
                    RequestedScopes = new string[] {},
                    PhotoUrl        = user.Profile.GetImageUrl(512).ToString(),
                });
            }
        }
示例#2
0
        public void HandleSignIn(Android.Gms.Tasks.Task task)
        {
            try
            {
                var result = task.Result as GoogleSignInAccount;

                if (!string.IsNullOrEmpty(result.ServerAuthCode))
                {
                    OnAuthCodeReceived?.Invoke(this, result.ServerAuthCode);
                }
                else
                {
                    OnLogin?.Invoke(this, new Data.GoogleUser()
                    {
                        Base            = result,
                        AuthCode        = result.ServerAuthCode,
                        Email           = result.Email,
                        FamilyName      = result.FamilyName,
                        GivenName       = result.GivenName,
                        GrantedScopes   = result.GrantedScopes.Select(x => x.ScopeUri).ToArray(),
                        RequestedScopes = result.RequestedScopes.Select(x => x.ScopeUri).ToArray(),
                        Id          = result.Id,
                        DisplayName = result.DisplayName,
                        IdToken     = result.IdToken,
                        PhotoUrl    = result.PhotoUrl.ToString(),
                    });
                }
            }
            catch (ApiException ex)
            {
                OnError?.Invoke(this, new Data.Error()
                {
                    Message = ex.Message,
                });
            }
        }