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); }
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; }