Ejemplo n.º 1
0
        internal GoogleClientManager()
        {
            if (CurrentActivity == null)
            {
                throw new GoogleClientNotInitializedErrorException(GoogleClientBaseException.ClientNotInitializedErrorMessage);
            }

            var gopBuilder = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn)
                             .RequestEmail();

            if (!string.IsNullOrWhiteSpace(_serverClientId))
            {
                gopBuilder.RequestServerAuthCode(_serverClientId, false);
            }

            if (!string.IsNullOrWhiteSpace(_clientId))
            {
                gopBuilder.RequestIdToken(_clientId);
            }

            foreach (var s in _initScopes)
            {
                gopBuilder.RequestScopes(new Scope(s));
            }

            GoogleSignInOptions googleSignInOptions = gopBuilder.Build();

            // Build a GoogleSignInClient with the options specified by gso.
            mGoogleSignInClient = GoogleSignIn.GetClient(CurrentActivity, googleSignInOptions);
        }
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
        internal GoogleClientManager()
        {
            if (CurrentActivity == null)
            {
                GoogleClientErrorEventArgs errorEventArgs = new GoogleClientErrorEventArgs();
                Exception exception = null;

                errorEventArgs.Error   = GoogleClientErrorType.SignInInternalError;
                errorEventArgs.Message = GoogleClientBaseException.SignInInternalErrorMessage;
                exception = new GoogleClientSignInInternalErrorException();

                _loginTcs.TrySetException(exception);
            }

            var gopBuilder = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn)
                             .RequestEmail();

            if (!string.IsNullOrWhiteSpace(_serverClientId))
            {
                gopBuilder.RequestServerAuthCode(_serverClientId, false);
            }

            if (!string.IsNullOrWhiteSpace(_clientId))
            {
                gopBuilder.RequestIdToken(_clientId);
            }

            foreach (var s in _initScopes)
            {
                gopBuilder.RequestScopes(new Scope(s));
            }

            GoogleSignInOptions googleSignInOptions = gopBuilder.Build();

            var googleApiClientBuilder = new GoogleApiClient.Builder(Application.Context)
                                         .AddConnectionCallbacks(this)
                                         .AddOnConnectionFailedListener(this)
                                         .AddApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions);

            foreach (var a in _initApis)
            {
                googleApiClientBuilder.AddApi(a);
            }

            GoogleApiClient = googleApiClientBuilder.Build();
        }
            public async Task <GoogleSignInResult> Authenticate(IGoogleAuthOptions options)
            {
                var googleScopes = options?.Scopes?.Select(s => new Scope(s))?.ToArray();

                var gsoBuilder = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn);

                if (!string.IsNullOrEmpty(options.ServerClientId))
                {
                    gsoBuilder = gsoBuilder.RequestIdToken(options.ServerClientId);
                }

                if (googleScopes != null && googleScopes.Any())
                {
                    gsoBuilder = gsoBuilder.RequestScopes(googleScopes.First(), googleScopes.Skip(1).ToArray());
                }

                if (options.FetchProfile)
                {
                    gsoBuilder = gsoBuilder.RequestProfile().RequestEmail();
                }

                var gso = gsoBuilder.Build();

                var activity = Plugin.SocialAuth.Droid.SocialAuth.CurrentActivity;

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

                googleApiClient.Connect();

                tcsSignIn = new TaskCompletionSource <GoogleSignInResult>();

                var result = await tcsSignIn.Task;

                googleApiClient.StopAutoManage(activity);

                return(result);
            }
        internal GoogleClientManager()
        {
            if (CurrentActivity == null)
            {
                throw new GoogleClientNotInitializedErrorException(GoogleClientBaseException.ClientNotInitializedErrorMessage);
            }

            var gopBuilder = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn)
                             .RequestEmail();

            if (!string.IsNullOrWhiteSpace(_serverClientId))
            {
                gopBuilder.RequestServerAuthCode(_serverClientId, false);
            }

            if (!string.IsNullOrWhiteSpace(_clientId))
            {
                gopBuilder.RequestIdToken(_clientId);
            }

            foreach (var s in _initScopes)
            {
                gopBuilder.RequestScopes(new Scope(s));
            }

            GoogleSignInOptions googleSignInOptions = gopBuilder.Build();

            var googleApiClientBuilder = new GoogleApiClient.Builder(Application.Context)
                                         .AddConnectionCallbacks(this)
                                         .AddOnConnectionFailedListener(this)
                                         .AddApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions);

            foreach (var a in _initApis)
            {
                googleApiClientBuilder.AddApi(a);
            }

            GoogleApiClient = googleApiClientBuilder.Build();
        }
        internal GoogleClientManager()
        {
            var gopBuilder = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn)
                             .RequestEmail();

            if (!string.IsNullOrWhiteSpace(_serverClientId))
            {
                gopBuilder.RequestServerAuthCode(_serverClientId, false);
            }

            if (!string.IsNullOrWhiteSpace(_clientId))
            {
                gopBuilder.RequestIdToken(_clientId);
            }

            GoogleSignInOptions googleSignInOptions = gopBuilder.Build();

            GoogleApiClient = new GoogleApiClient.Builder(Application.Context)
                              .AddConnectionCallbacks(this)
                              .AddOnConnectionFailedListener(this)
                              .AddApi(Auth.GOOGLE_SIGN_IN_API, googleSignInOptions)
                              .AddScope(new Scope(Scopes.Profile))
                              .Build();
        }