Java Code Examples for com.google.android.gms.auth.api.signin.GoogleSignInOptions

The following examples show how to use com.google.android.gms.auth.api.signin.GoogleSignInOptions. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Passbook   Source File: GameSyncService.java    License: Apache License 2.0 9 votes vote down vote up
@Override
public SyncService initialize(Activity context) {
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
            .requestScopes(Drive.SCOPE_APPFOLDER)
            //.requestScopes(Games.SCOPE_GAMES)
            .build();
    mGoogleSignClient = GoogleSignIn.getClient(context, gso);
    mSignInAccount = GoogleSignIn.getLastSignedInAccount(context);
    return this;
}
 
Example 2
Source Project: science-journal   Source File: GoogleAccountsProvider.java    License: Apache License 2.0 9 votes vote down vote up
public GoogleAccountsProvider(Context context) {
  super(context);
  this.context = context;
  setShowSignInActivityIfNotSignedIn(false);
  GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
      .requestEmail()
      .build();
  googleSignInClient = GoogleSignIn.getClient(context, gso);

  GoogleSignInAccount googleSignInAccount = GoogleSignIn.getLastSignedInAccount(context);
  if (googleSignInAccount != null) {
    signInCurrentAccount(googleSignInAccount);
  }
}
 
Example 3
Source Project: PGSGP   Source File: PlayGameServices.java    License: MIT License 6 votes vote down vote up
private void initializePlayGameServices(boolean enableSaveGamesFunctionality) {
    GoogleSignInOptions signInOptions = null;
     
    if (enableSaveGamesFunctionality) {
        GoogleSignInOptions.Builder signInOptionsBuilder = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
        signInOptionsBuilder.requestScopes(Drive.SCOPE_APPFOLDER).requestId();
        signInOptions = signInOptionsBuilder.build();
    } else {
        signInOptions = GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN;
    }
     
    godotCallbacksUtils = new GodotCallbacksUtils();
    connectionController = new ConnectionController(appActivity, signInOptions, godotCallbacksUtils);
    signInController = new SignInController(appActivity, godotCallbacksUtils, connectionController);
    achievementsController = new AchievementsController(appActivity, connectionController, godotCallbacksUtils);
    leaderboardsController = new LeaderboardsController(appActivity, godotCallbacksUtils, connectionController);
    eventsController = new EventsController(appActivity, connectionController, godotCallbacksUtils);
    playerStatsController = new PlayerStatsController(appActivity, connectionController, godotCallbacksUtils);
    savedGamesController = new SavedGamesController(appActivity, godotCallbacksUtils, connectionController);

    googleSignInClient = GoogleSignIn.getClient(appActivity, signInOptions);
}
 
Example 4
Source Project: SEAL-Demo   Source File: AuthUtil.java    License: MIT License 6 votes vote down vote up
/**
 * Allows to logout from Google account
 *
 * @param context the activity context
 */
private static void logoutGoogleProvider(final Context context) {
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(context.getString(R.string.googleClientId))
            .requestProfile()
            .build();
    // Build a GoogleSignInClient with the options specified by gso.
    GoogleSignInClient mGoogleSignInClient = GoogleSignIn.getClient(context, gso);
    // Check for existing Google Sign In account, if the user is already signed in
    // the GoogleSignInAccount will be non-null.
    GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(context);
    if (account != null) {
        mGoogleSignInClient.signOut()
                .addOnCompleteListener(((Activity) context), new OnCompleteListener<Void>() {
                    @Override
                    public void onComplete(@NonNull Task<Void> task) {
                        ApplicationState.setIsKeysCreated(false);
                        // delete all user info
                        deleteUserTokenAndInfo(context);
                        // load sign in
                        Intent myIntent = new Intent(context, SignInActivity.class);
                        ((Activity) context).startActivityForResult(myIntent, SIGN_IN_ACTIVITY_REQUEST_CODE);
                    }
                });
    }
}
 
Example 5
Source Project: shortyz   Source File: PlayGames.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if(thisView != null){
        return thisView;
    }

    this.mGoogleSignInClient = GoogleSignIn.getClient(this.getContext(),
            new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN).build());
    View v = inflater.inflate(R.layout.slide_playgames, container, false);
    initView(v);
    text = (TextView) v.findViewById(R.id.slideText);
    (this.signInButton = v.findViewById(R.id.sign_in_button)).setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            // start the sign-in flow
            signInSilently();
        }

    });
    if(isSignedIn()){
        done();
    } else {
        this.signInButton.setVisibility(View.VISIBLE);
    }
    return v;
}
 
Example 6
Source Project: ShareLoginPayUtil   Source File: GoogleLoginInstance.java    License: Apache License 2.0 6 votes vote down vote up
public GoogleLoginInstance(Activity activity, LoginListener listener, boolean fetchUserInfo) {
    super(activity, listener, fetchUserInfo);
    mClientId = ShareManager.CONFIG.getGoogleClientId();
    mClientSecret = ShareManager.CONFIG.getGoogleClientSecret();
    mClient = new OkHttpClient.Builder().build();

    GoogleSignInOptions signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(mClientId)
            .requestScopes(new Scope(Scopes.DRIVE_APPFOLDER), new Scope(Scopes.OPEN_ID), new Scope(Scopes.PLUS_ME))
            .requestServerAuthCode(mClientId)
            .requestProfile()
            .requestEmail()
            .build();

    mGoogleSignInClient = GoogleSignIn.getClient(activity, signInOptions);
}
 
Example 7
Source Project: Android-9-Development-Cookbook   Source File: MainActivity.java    License: MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    findViewById(R.id.signInButton).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            signIn();
        }
    });
    GoogleSignInOptions googleSignInOptions = new GoogleSignInOptions
            .Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .build();
    mGoogleSignInClient = GoogleSignIn.getClient(this, googleSignInOptions);
}
 
Example 8
Source Project: UberClone   Source File: Home.java    License: MIT License 6 votes vote down vote up
private void verifyGoogleAccount() {
    GoogleSignInOptions gso=new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().build();
    mGoogleApiClient=new GoogleApiClient.Builder(this)
            .enableAutoManage(this, this)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();
    OptionalPendingResult<GoogleSignInResult> opr=Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
    if (opr.isDone()){
        GoogleSignInResult result= opr.get();
        handleSignInResult(result);
    }else {
        opr.setResultCallback(new ResultCallback<GoogleSignInResult>() {
            @Override
            public void onResult(@NonNull GoogleSignInResult googleSignInResult) {
                handleSignInResult(googleSignInResult);
            }
        });
    }
}
 
Example 9
Source Project: socialmediasignup   Source File: GoogleSignUpActivity.java    License: MIT License 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    String clientId = SocialMediaSignUpUtils.getMetaDataValue(this, getString(R.string.com_ahmedadel_socialmediasignup_googleWebClientId));

    GoogleSignInOptions.Builder gsoBuilder = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestId()
            .requestProfile()
            .requestEmail()
            .requestIdToken(clientId);

    setupScopes(gsoBuilder);

    googleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this, this)
            .addConnectionCallbacks(this)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gsoBuilder.build())
            .build();
}
 
Example 10
Source Project: android-basic-samples   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  // Create the client used to sign in.
  mGoogleSignInClient = GoogleSignIn.getClient(this, GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);

  // set up a click listener for everything we care about
  for (int id : CLICKABLES) {
    findViewById(id).setOnClickListener(this);
  }

  switchToMainScreen();
  checkPlaceholderIds();
}
 
Example 11
Source Project: google-signin   Source File: Utils.java    License: MIT License 6 votes vote down vote up
static GoogleSignInOptions getSignInOptions(
        final Scope[] scopes,
        final String webClientId,
        final boolean offlineAccess,
        final boolean forceCodeForRefreshToken,
        final String accountName,
        final String hostedDomain
) {
    GoogleSignInOptions.Builder googleSignInOptionsBuilder = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestScopes(new Scope(Scopes.EMAIL), scopes);
    if (webClientId != null && !webClientId.isEmpty()) {
        googleSignInOptionsBuilder.requestIdToken(webClientId);
        if (offlineAccess) {
            googleSignInOptionsBuilder.requestServerAuthCode(webClientId, forceCodeForRefreshToken);
        }
    }
    if (accountName != null && !accountName.isEmpty()) {
        googleSignInOptionsBuilder.setAccountName(accountName);
    }
    if (hostedDomain != null && !hostedDomain.isEmpty()) {
        googleSignInOptionsBuilder.setHostedDomain(hostedDomain);
    }
    return googleSignInOptionsBuilder.build();
}
 
Example 12
Source Project: NaviBee   Source File: LoginActivity.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
//        setSupportActionBar((Toolbar) findViewById(R.id.login_logo_toolbar));

        mAuth = FirebaseAuth.getInstance();

        if (!checkSignIn()) {
            // Configure Google Sign In
            GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                    .requestIdToken(getString(R.string.default_web_client_id))
                    .requestEmail()
                    .build();
            // Build a GoogleSignInClient with the options specified by gso.
            mGoogleSignInClient = GoogleSignIn.getClient(this, gso);


            findViewById(R.id.sign_in_button).setOnClickListener(this);
        }
    }
 
Example 13
private void signInSilently() {
    GoogleSignInOptions signInOptions = GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN;
    GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
    if (GoogleSignIn.hasPermissions(account, signInOptions.getScopeArray())) {
        googleSignedIn(account);
    } else {
        GoogleSignInClient signInClient = GoogleSignIn.getClient(this, signInOptions);
        signInClient.silentSignIn().addOnCompleteListener(this, task -> {
            if (task.isSuccessful()) {
                googleSignedIn(task.getResult());
            } else {
                if (Prefs.getBoolean(PK.SHOULD_PROMPT_GOOGLE_PLAY, true)) {
                    Intent intent = signInClient.getSignInIntent();
                    startActivityForResult(intent, GOOGLE_SIGN_IN_CODE);
                }
            }
        });
    }
}
 
Example 14
Source Project: android-basic-samples   Source File: SkeletonActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  // Create the Google API Client with access to Games
  // Create the client used to sign in.
  mGoogleSignInClient = GoogleSignIn.getClient(this, GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);

  // Setup signin and signout buttons
  findViewById(R.id.sign_out_button).setOnClickListener(this);
  findViewById(R.id.sign_in_button).setOnClickListener(this);

  mDataView = findViewById(R.id.data_view);
  mTurnTextView = findViewById(R.id.turn_counter_view);
  checkPlaceholderIds();
}
 
Example 15
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sign_in);

    // Assign fields
    mSignInButton = (SignInButton) findViewById(R.id.sign_in_button);

    // Set click listeners
    mSignInButton.setOnClickListener(this);

    // Configure Google Sign In
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(R.string.default_web_client_id))
            .requestEmail()
            .build();
    mSignInClient = GoogleSignIn.getClient(this, gso);

    // Initialize FirebaseAuth
    mFirebaseAuth = FirebaseAuth.getInstance();
}
 
Example 16
Source Project: easygoogle   Source File: SignIn.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Api.ApiOptions.HasOptions getOptionsFor(Api<? extends Api.ApiOptions> api) {
    if (Auth.GOOGLE_SIGN_IN_API.equals(api)) {
        GoogleSignInOptions.Builder googleSignInOptions =  new GoogleSignInOptions.Builder(
                GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestEmail();

        // Check server client id for OAuth, so GoogleSignInAccount.getIdToken(); is non-null
        String serverClientId = getFragment().getServerClientId();
        if(serverClientId != null){
            googleSignInOptions.requestIdToken(serverClientId);
        }
        return googleSignInOptions.build();
    } else {
        return super.getOptionsFor(api);
    }
}
 
Example 17
Source Project: gdx-fireapp   Source File: GoogleAuthTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
    public void revokeAccess_ok() {
        // Given
        GoogleAuth googleAuth = new GoogleAuth();
        Task task = Mockito.mock(Task.class);
        final Task task2 = Mockito.mock(Task.class);
        Mockito.when(task2.isSuccessful()).thenReturn(true);
        Mockito.when(googleSignInClient.revokeAccess()).thenReturn(task);
        Mockito.when(task.addOnCompleteListener(Mockito.any(OnCompleteListener.class))).thenAnswer(new Answer<Object>() {
            @Override
            public Object answer(InvocationOnMock invocation) {
                ((OnCompleteListener) invocation.getArgument(0)).onComplete(task2);
                return null;
            }
        });

        // When
        FuturePromise promise = (FuturePromise) spy(googleAuth.revokeAccess().subscribe());

        // Then
        PowerMockito.verifyStatic(GoogleSignIn.class, VerificationModeFactory.times(1));
        GoogleSignIn.getClient((Activity) Mockito.refEq(Gdx.app), Mockito.any(GoogleSignInOptions.class));
        Mockito.verify(googleSignInClient, VerificationModeFactory.times(1)).revokeAccess();
//        Mockito.verify(promise, VerificationModeFactory.times(1)).doComplete(Mockito.isNull());
    }
 
Example 18
Source Project: gdx-fireapp   Source File: GoogleAuthTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
    public void revokeAccess_fail() {
        // Given
        GoogleAuth googleAuth = new GoogleAuth();
        Task task = Mockito.mock(Task.class);
        final Task task2 = Mockito.mock(Task.class);
        Mockito.when(task2.isSuccessful()).thenReturn(false);
        Mockito.when(googleSignInClient.revokeAccess()).thenReturn(task);
        Mockito.when(task.addOnCompleteListener(Mockito.any(OnCompleteListener.class))).thenAnswer(new Answer<Object>() {
            @Override
            public Object answer(InvocationOnMock invocation) {
                ((OnCompleteListener) invocation.getArgument(0)).onComplete(task2);
                return null;
            }
        });

        // When
        FuturePromise promise = (FuturePromise) spy(googleAuth.revokeAccess().silentFail().subscribe());

        // Then
        PowerMockito.verifyStatic(GoogleSignIn.class, VerificationModeFactory.times(1));
        GoogleSignIn.getClient((Activity) Mockito.refEq(Gdx.app), Mockito.any(GoogleSignInOptions.class));
        Mockito.verify(googleSignInClient, VerificationModeFactory.times(1)).revokeAccess();
//        Mockito.verify(promise, VerificationModeFactory.times(1)).doFail(Mockito.nullable(Exception.class));
    }
 
Example 19
Source Project: social-app-android   Source File: GoogleApiHelper.java    License: Apache License 2.0 6 votes vote down vote up
public static GoogleApiClient createGoogleApiClient(FragmentActivity fragmentActivity) {
    GoogleApiClient.OnConnectionFailedListener failedListener;

    if (fragmentActivity instanceof GoogleApiClient.OnConnectionFailedListener) {
        failedListener = (GoogleApiClient.OnConnectionFailedListener) fragmentActivity;
    } else {
        throw new IllegalArgumentException(fragmentActivity.getClass().getSimpleName() + " should implement OnConnectionFailedListener");
    }

    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(fragmentActivity.getResources().getString(R.string.google_web_client_id))
            .requestEmail()
            .build();

    return new GoogleApiClient.Builder(fragmentActivity)
            .enableAutoManage(fragmentActivity, failedListener)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();
}
 
Example 20
Source Project: google-signin   Source File: RNGoogleSigninModule.java    License: MIT License 6 votes vote down vote up
@ReactMethod
public void configure(
        final ReadableMap config,
        final Promise promise
) {
    final ReadableArray scopes = config.hasKey("scopes") ? config.getArray("scopes") : Arguments.createArray();
    final String webClientId = config.hasKey("webClientId") ? config.getString("webClientId") : null;
    final boolean offlineAccess = config.hasKey("offlineAccess") && config.getBoolean("offlineAccess");
    final boolean forceCodeForRefreshToken = config.hasKey("forceCodeForRefreshToken") && config.getBoolean("forceCodeForRefreshToken");
    final String accountName = config.hasKey("accountName") ? config.getString("accountName") : null;
    final String hostedDomain = config.hasKey("hostedDomain") ? config.getString("hostedDomain") : null;

    GoogleSignInOptions options = getSignInOptions(createScopesArray(scopes), webClientId, offlineAccess, forceCodeForRefreshToken, accountName, hostedDomain);
    _apiClient = GoogleSignIn.getClient(getReactApplicationContext(), options);
    promise.resolve(null);
}
 
Example 21
Source Project: aptoide-client   Source File: LoginActivity.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void setUpGoogle() {
    final View googleSignIn = findViewById(R.id.g_sign_in_button);
    final int connectionResult = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this);
    final Collection<Integer> badResults = Arrays.asList(ConnectionResult.SERVICE_MISSING, ConnectionResult.SERVICE_DISABLED);
    final boolean gmsAvailable = BuildConfig.GMS_CONFIGURED && !badResults.contains(connectionResult);
    if (!gmsAvailable) {
        googleSignIn.setVisibility(View.GONE);
        return;
    }
    final GoogleSignInOptions gso = new GoogleSignInOptions
            .Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .requestServerAuthCode(BuildConfig.GMS_SERVER_ID)
            .build();
    final GoogleApiClient client = new GoogleApiClient.Builder(this)
            .enableAutoManage(this, this)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();
    googleSignIn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(client);
            startActivityForResult(signInIntent, REQ_SIGN_IN_GOOGLE);
        }
    });
}
 
Example 22
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
    .requestId()
    .requestProfile()
    .requestIdToken(getIntent().getStringExtra(EXTRA_CLIENT_ID))
    .requestEmail()
    .build();

  GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this)
    .enableAutoManage(this, this)
    .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
    .build();

  Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(googleApiClient);
  startActivityForResult(signInIntent, RC_SIGN_IN);
}
 
Example 23
Source Project: jterm-cswithandroid   Source File: SignInActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sign_in);

    // Assign fields
    mSignInButton = (SignInButton) findViewById(R.id.sign_in_button);

    // Set click listeners
    mSignInButton.setOnClickListener(this);

    // Configure Google Sign In
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(R.string.default_web_client_id))
            .requestEmail()
            .build();
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();

    // Initialize FirebaseAuth
    mFirebaseAuth = FirebaseAuth.getInstance();

}
 
Example 24
Source Project: friendspell   Source File: GoogleApiClientBridge.java    License: Apache License 2.0 6 votes vote down vote up
public String init(
    Activity activity,
    GoogleApiClient.ConnectionCallbacks connectedListener,
    GoogleApiClient.OnConnectionFailedListener connectionFailedListener) {
  // 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.DEFAULT_SIGN_IN)
          .requestEmail()
          .requestId()
          .requestProfile()
          .build();

  GoogleApiClient googleApiClient = new GoogleApiClient.Builder(activity)
      .addConnectionCallbacks(connectedListener)
      .addOnConnectionFailedListener(connectionFailedListener)
      .addApi(Plus.API)
      .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
      .addApi(Nearby.MESSAGES_API)
      .build();
  String token = UUID.randomUUID().toString();
  clients.put(token, googleApiClient);
  return token;
}
 
Example 25
Source Project: capacitor-firebase-auth   Source File: GoogleProviderHandler.java    License: MIT License 5 votes vote down vote up
@Override
public void init(CapacitorFirebaseAuth plugin) {
    this.plugin = plugin;

    String[] permissions = Config.getArray(CONFIG_KEY_PREFIX + "permissions.google", new String[0]);

    GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance();
    int result = googleAPI.isGooglePlayServicesAvailable(this.plugin.getContext());
    if (result == ConnectionResult.SUCCESS) {
        Log.d(GOOGLE_TAG, "Google Api is Available.");
    } else {
        Log.w(GOOGLE_TAG, "Google Api is not Available.");
    }

    GoogleSignInOptions.Builder gsBuilder = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(this.plugin.getContext().getString(R.string.default_web_client_id))
            .requestEmail();

    for (String permission : permissions) {
        try {
            gsBuilder.requestScopes(new Scope(permission));
        } catch (Exception e) {
            Log.w(GOOGLE_TAG, String.format("Failure requesting the scope at index %s", permission));
        }
    }

    GoogleSignInOptions gso = gsBuilder.build();
    this.mGoogleSignInClient = GoogleSignIn.getClient(this.plugin.getActivity(), gso);
}
 
Example 26
Source Project: google-services   Source File: IdTokenActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Views
    mIdTokenTextView = findViewById(R.id.detail);
    mRefreshButton = findViewById(R.id.button_optional_action);
    mRefreshButton.setText(R.string.refresh_token);

    // Button click listeners
    findViewById(R.id.sign_in_button).setOnClickListener(this);
    findViewById(R.id.sign_out_button).setOnClickListener(this);
    findViewById(R.id.disconnect_button).setOnClickListener(this);
    mRefreshButton.setOnClickListener(this);

    // For sample only: make sure there is a valid server client ID.
    validateServerClientID();

    // [START configure_signin]
    // Request only the user's ID token, which can be used to identify the
    // user securely to your backend. This will contain the user's basic
    // profile (name, profile picture URL, etc) so you should not need to
    // make an additional call to personalize your application.
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(R.string.server_client_id))
            .requestEmail()
            .build();
    // [END configure_signin]

    // Build GoogleAPIClient with the Google Sign-In API and the above options.
    mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
}
 
Example 27
Source Project: wear-os-samples   Source File: GoogleSignInActivity.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Configures the GoogleApiClient used for sign in. Requests scopes profile and email.
 */
protected void setupGoogleSignInClient() {
    GoogleSignInOptions gso = new GoogleSignInOptions
            .Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestProfile()
            .requestEmail()
            .build();
    mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
}
 
Example 28
Source Project: andela-med-manager   Source File: AuthActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_auth);
    ButterKnife.bind(this);

    addUserViewModel = ViewModelProviders.of(this).get(AddUserViewModel.class);

    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .build();

    // Build a GoogleApiClient with access to the Google Sign-In Api and the
    // options specified by gso.
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this /* FragmentActivitgit y */, this /* OnConnectionFailedListener */)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();

    loginButton.setOnClickListener(v -> {
        //Check Internet Connection
        //  if (NetworkUtil.isConnected(this))
        googleSignIn();

    });
}
 
Example 29
Source Project: FastAccess   Source File: LoginView.java    License: GNU General Public License v3.0 5 votes vote down vote up
private GoogleSignInOptions getSignInOptions() {
    if (signInOptions == null) {
        signInOptions = new GoogleSignInOptions
                .Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestIdToken(getString(R.string.default_web_client_id))
                .requestEmail()
                .build();
    }
    return signInOptions;
}
 
Example 30
Source Project: google-services   Source File: ServerAuthCodeActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Views
    mAuthCodeTextView = findViewById(R.id.detail);

    // Button click listeners
    findViewById(R.id.sign_in_button).setOnClickListener(this);
    findViewById(R.id.sign_out_button).setOnClickListener(this);
    findViewById(R.id.disconnect_button).setOnClickListener(this);

    // For sample only: make sure there is a valid server client ID.
    validateServerClientID();

    // [START configure_signin]
    // Configure sign-in to request offline access to the user's ID, basic
    // profile, and Google Drive. The first time you request a code you will
    // be able to exchange it for an access token and refresh token, which
    // you should store. In subsequent calls, the code will only result in
    // an access token. By asking for profile access (through
    // DEFAULT_SIGN_IN) you will also get an ID Token as a result of the
    // code exchange.
    String serverClientId = getString(R.string.server_client_id);
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestScopes(new Scope(Scopes.DRIVE_APPFOLDER))
            .requestServerAuthCode(serverClientId)
            .requestEmail()
            .build();
    // [END configure_signin]

    mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
}