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); }
//====================================================== #region Google //Event Click login using google private void GoogleSignInButtonOnClick(object sender, EventArgs e) { try { if (MGoogleSignInClient == null) { // Configure sign-in to request the user's ID, email address, and basic profile. ID and basic profile are included in DEFAULT_SIGN_IN. var gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn) .RequestIdToken(AppSettings.ClientId) .RequestScopes(new Scope(Scopes.Profile)) .RequestScopes(new Scope(Scopes.PlusMe)) .RequestScopes(new Scope(Scopes.DriveAppfolder)) .RequestServerAuthCode(AppSettings.ClientId) .RequestProfile().RequestEmail().Build(); MGoogleSignInClient ??= GoogleSignIn.GetClient(this, gso); } var signInIntent = MGoogleSignInClient.SignInIntent; StartActivityForResult(signInIntent, 0); } catch (Exception exception) { Methods.DisplayReportResultTrack(exception); } }
public void Logout() { var gsoBuilder = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn).RequestEmail(); GoogleSignIn.GetClient(_context, gsoBuilder.Build())?.SignOut(); _googleApiClient.Disconnect(); }
public GoogleService(Activity activity) { _activity = activity; var gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn) .RequestIdToken(activity.GetString(Resource.String.default_web_client_id)) .RequestEmail() .Build(); _client = GoogleSignIn.GetClient(activity, gso); }
// Third partys private void ImgGooglePlay_Click(object sender, EventArgs e) { string serverClientId = Resources.GetString(Resource.String.server_client_id); GoogleSignInOptions googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultGamesSignIn) .RequestServerAuthCode(serverClientId) .Build(); GoogleSignInClient googleSignInClient = GoogleSignIn.GetClient(this, googleSignInOptions); Intent signInIntent = googleSignInClient.SignInIntent; StartActivityForResult(signInIntent, 9003); }
private GoogleSignInClient BuildSignInClient() { var signInOptions = new GoogleSignInOptions .Builder(GoogleSignInOptions.DefaultSignIn) //.RequestScopes(DriveClass.ScopeFile, DriveClass.ScopeAppfolder) .RequestProfile() .RequestEmail() .Build(); var activity = _fromActivity ? _activity : _fragment.Activity; return(GoogleSignIn.GetClient(activity, signInOptions)); }
private GoogleClientManager() { if (currentActivity == null) { throw new GoogleClientNotInitializedErrorException(GoogleClientBaseException.ClientNotInitializedErrorMessage); } var googleSignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn) .RequestIdToken(Constants.GoogleRequestIdToken) .RequestEmail() .RequestScopes(new Scope(Scopes.Profile)) .Build(); googleSignInClient = GoogleSignIn.GetClient(currentActivity, googleSignInOptions); }
private void ImgGoogle_Click(object sender, EventArgs e) { string serverClientId = Resources.GetString(Resource.String.server_client_id); const int RcSignIn = 9001; // Configure sign-in to request the user's ID, email address, and basic // profile. ID and basic profile are included in DEFAULT_SIGN_IN. GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn) .RequestProfile() .RequestIdToken(serverClientId) .Build(); GoogleSignInClient googleSignClient = GoogleSignIn.GetClient(this, gso); Intent signInIntent = googleSignClient.SignInIntent; StartActivityForResult(signInIntent, RcSignIn); }
public void RequestFitnessPermissions() { //we have to do all this hullaballoo because Xamarin.PlayServices.Fitness does not contain a constructor for FitnessOptions //IntPtr classRef = JNIEnv.FindClass("com/google/android/gms/fitness/FitnessOptions$Builder"); //IntPtr constructorId = JNIEnv.GetMethodID(classRef, "<init>", "I(V)"); //IntPtr referenceInstance = JNIEnv.NewObject(classRef, constructorId); //var fitnessApiOptions = new FitnessOptions.Builder() var fitnessApiOptions = FitnessOptions.InvokeBuilder() .AddDataType(Android.Gms.Fitness.Data.DataType.AggregateActivitySummary, FitnessOptions.AccessWrite) .AddDataType(Android.Gms.Fitness.Data.DataType.AggregateSpeedSummary, FitnessOptions.AccessWrite) .Build(); account = GoogleSignIn.GetLastSignedInAccount(this); if (account == null && !googleLoginInProgress) { GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn) .RequestEmail() .Build(); var signInClient = GoogleSignIn.GetClient(this, gso); googleLoginInProgress = true; StartActivityForResult(signInClient.SignInIntent, REQUEST_GOOGLE_SIGN_IN); return; } if (!GoogleSignIn.HasPermissions(account, fitnessApiOptions)) { GoogleSignIn.RequestPermissions( this, REQUEST_FITNESS_PERMISSIONS, account, fitnessApiOptions); } else { HasGoogleFitnessPermissions = true; GoogleFitnessPermissionsUpdated?.Invoke(HasGoogleFitnessPermissions); } }
public void Initialize(AuthType type, string clientId = "") { authType = type; switch (authType) { case AuthType.Google: var gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn) .RequestIdToken(clientId) .RequestProfile() .RequestEmail() .Build(); signInClient = GoogleSignIn.GetClient(Xamarin.Essentials.Platform.CurrentActivity, gso); break; case AuthType.Facebook: callbackManager = CallbackManagerFactory.Create(); LoginManager.Instance.RegisterCallback(callbackManager, this); break; } }
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; }
private void InitSocialLogins() { try { //#Facebook if (AppSettings.ShowFacebookLogin) { LoginButton loginButton = new LoginButton(this); MprofileTracker = new FbMyProfileTracker(); MprofileTracker.StartTracking(); BtnFacebook = FindViewById <Button>(Resource.Id.btn_facebook); BtnFacebook.Visibility = ViewStates.Visible; BtnFacebook.Click += BtnFacebookOnClick; MprofileTracker.MOnProfileChanged += MprofileTrackerOnMOnProfileChanged; loginButton.SetPermissions(new List <string> { "email", "public_profile" }); MFbCallManager = CallbackManagerFactory.Create(); loginButton.RegisterCallback(MFbCallManager, this); //FB accessToken var accessToken = AccessToken.CurrentAccessToken; var isLoggedIn = accessToken != null && !accessToken.IsExpired; if (isLoggedIn && Profile.CurrentProfile != null) { LoginManager.Instance.LogOut(); } string hashId = Methods.App.GetKeyHashesConfigured(this); Console.WriteLine(hashId); } else { BtnFacebook = FindViewById <Button>(Resource.Id.btn_facebook); BtnFacebook.Visibility = ViewStates.Gone; } //#Google if (AppSettings.ShowGoogleLogin) { // Configure sign-in to request the user's ID, email address, and basic profile. ID and basic profile are included in DEFAULT_SIGN_IN. var gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn) .RequestIdToken(AppSettings.ClientId) .RequestScopes(new Scope(Scopes.Profile)) .RequestScopes(new Scope(Scopes.PlusMe)) .RequestScopes(new Scope(Scopes.DriveAppfolder)) .RequestServerAuthCode(AppSettings.ClientId) .RequestProfile().RequestEmail().Build(); MGoogleSignInClient = GoogleSignIn.GetClient(this, gso); BtnGoogle = FindViewById <Button>(Resource.Id.btn_google); BtnGoogle.Click += GoogleSignInButtonOnClick; } else { BtnGoogle = FindViewById <Button>(Resource.Id.btn_google); BtnGoogle.Visibility = ViewStates.Gone; } } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
public GoogleAuth(Activity activity, string requestToken) { _signInClient = GoogleSignIn.GetClient(activity, CreateGoogleSignInOptions(requestToken)); }