GetGoogleClientId() public static method

public static GetGoogleClientId ( string clientId ) : string
clientId string
return string
Ejemplo n.º 1
0
            public async Task <GoogleUser> Authenticate(GoogleAuthenticator authenticator)
            {
                authenticatorReference = new WeakReference(authenticator);
                SignIn.ClientId        = GoogleAuthenticator.GetGoogleClientId(authenticator.ClientId);
                if (!string.IsNullOrWhiteSpace(authenticator.ServerClientId))
                {
                    SignIn.ServerClientId = GoogleAuthenticator.GetGoogleClientId(authenticator.ServerClientId);
                }


                var window          = UIApplication.SharedApplication.KeyWindow;
                var root            = window.RootViewController;
                UIViewController vc = root;

                while (vc.PresentedViewController != null)
                {
                    vc = vc.PresentedViewController;
                }

                SignIn.PresentingViewController = vc;
                SignIn.Scopes   = authenticator.Scope.ToArray();
                SignIn.Delegate = this;
                SignIn.SignInUser();
                return(await tcs.Task);
            }
Ejemplo n.º 2
0
            public async Task <GoogleSignInResult> Authenticate(GoogleAuthenticator authenticator)
            {
                var activity = CurrentActivity;

                CheckGooglePlayServices(activity);

                try
                {
                    var googleScopes = authenticator.Scope?.Select(s => new Scope(s))?.ToArray();
                    var clientID     = GoogleAuthenticator.GetGoogleClientId(authenticator.ClientId);
                    var serverId     = GoogleAuthenticator.GetGoogleClientId(authenticator.ServerClientId);
                    var gsoBuilder   = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn)
                                       .RequestEmail();

                    if (serverId != null)
                    {
                        gsoBuilder.RequestIdToken(serverId);
                    }

                    if (authenticator.Scope != null)
                    {
                        foreach (var scope in authenticator.Scope)
                        {
                            gsoBuilder.RequestScopes(new Scope(scope));
                        }
                    }

                    var gso = gsoBuilder.Build();

                    googleApiClient = new GoogleApiClient.Builder(activity)
                                      .AddConnectionCallbacks(this)
                                      .AddOnConnectionFailedListener(this)
                                      .AddApi(Auth.GOOGLE_SIGN_IN_API, gso)
                                      .Build();
                    googleApiClient.Connect();

                    var signInIntent = Auth.GoogleSignInApi.GetSignInIntent(googleApiClient);

                    if (tcsSignIn != null && !tcsSignIn.Task.IsCompleted)
                    {
                        tcsSignIn.TrySetCanceled();
                    }

                    tcsSignIn = new TaskCompletionSource <GoogleSignInResult>();

                    activity.StartActivityForResult(signInIntent, SIGN_IN_REQUEST_CODE);

                    var success = await tcsSignIn.Task;
                    return(success);
                }
                finally
                {
                    googleApiClient?.UnregisterConnectionCallbacks(this);
                    googleApiClient?.Disconnect();
                }
            }
Ejemplo n.º 3
0
 public async Task <GoogleUser> Authenticate(GoogleAuthenticator authenticator)
 {
     authenticatorReference = new WeakReference(authenticator);
     SignIn.ClientID        = GoogleAuthenticator.GetGoogleClientId(authenticator.ClientId);
     SignIn.ServerClientID  = GoogleAuthenticator.GetGoogleClientId(authenticator.ServerClientId);
     SignIn.Scopes          = authenticator.Scope.ToArray();
     SignIn.Delegate        = this;
     SignIn.UIDelegate      = this;
     SignIn.SignInUser();
     return(await tcs.Task);
 }
Ejemplo n.º 4
0
        static async void Login(WebAuthenticator authenticator)
        {
            var currentActivity = activityLifecycle.CurrentActivity;

            var googleAuth = authenticator as GoogleAuthenticator;

            googleSignInProvider = new GoogleSignInProvider();

            GoogleSignInResult result = null;

            try
            {
                result = await googleSignInProvider.Authenticate(GoogleAuthenticator.GetGoogleClientId(googleAuth.ClientId), googleAuth.Scope.ToArray());

                if (result == null || result.Status.IsCanceled || result.Status.IsInterrupted)
                {
                    googleAuth.OnCancelled();
                    return;
                }

                if (!result.IsSuccess)
                {
                    googleAuth.OnError(result.Status.StatusMessage);
                    return;
                }

                //var accessToken = Android.Gms.Auth.GoogleAuthUtil.GetToken(currentActivity, result.SignInAccount.Email, string.Join (" ", tokenScopes));


                var androidAccount = Android.Accounts.AccountManager.FromContext(currentActivity)
                                     ?.GetAccounts()
                                     ?.FirstOrDefault(a => a.Name?.Equals(result?.SignInAccount?.Email, StringComparison.InvariantCultureIgnoreCase) ?? false);

                var tokenScopes = googleAuth.Scope.Select(s => "oauth2:" + s);

                var accessToken = await Task.Run(() =>
                {
                    return(Android.Gms.Auth.GoogleAuthUtil.GetToken(currentActivity, androidAccount, string.Join(" ", tokenScopes)));
                });

                googleAuth.OnRecievedAuthCode(accessToken);
            }
            catch (Exception ex)
            {
                googleAuth.OnError(ex.Message);
            }
        }