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); }
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.RequestServerAuthCode(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(); } }
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(); }
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(); }
public void Initialize(Activity activity, string serverClientId, bool requestProfile, bool requestEmail) { var builder = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn); if (requestProfile) { builder = builder.RequestProfile(); } if (requestEmail) { builder = builder.RequestEmail(); } if (!string.IsNullOrEmpty(serverClientId)) { builder = builder.RequestServerAuthCode(serverClientId); } googleSignInOptions = builder.Build(); googleSignInClient = GoogleSignIn.GetClient(activity, googleSignInOptions); Activity = activity; }