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

The following examples show how to use com.google.android.gms.auth.api.signin.GoogleSignInOptions#Builder . 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 File: PlayGameServices.java    From PGSGP with 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 2
Source File: GoogleSignUpActivity.java    From socialmediasignup with 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 3
Source File: PlayGamesPlugin.java    From play_games with MIT License 6 votes vote down vote up
private void signOut() {
    GoogleSignInOptions.Builder builder = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
    GoogleSignInOptions opts = builder.build();
    GoogleSignInClient signInClient = GoogleSignIn.getClient(registrar.activity(), opts);
    signInClient.signOut().addOnSuccessListener(new OnSuccessListener<Void>() {
        @Override
        public void onSuccess(Void aVoid) {
            currentAccount = null;
            Map<String, Object> successMap = new HashMap<>();
            successMap.put("type", "SUCCESS");
            result(successMap);
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            error("ERROR_SIGN_OUT", e);
            Log.i(TAG, "Failed to signout", e);
        }
    });

}
 
Example 4
Source File: SignIn.java    From easygoogle with 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 5
Source File: Utils.java    From google-signin with 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 6
Source File: MainActivity.java    From identity-samples with Apache License 2.0 5 votes vote down vote up
private void buildClients(String accountName) {
    GoogleSignInOptions.Builder gsoBuilder = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail();

    if (accountName != null) {
        gsoBuilder.setAccountName(accountName);
    }

    mCredentialsClient = Credentials.getClient(this);
    mSignInClient = GoogleSignIn.getClient(this, gsoBuilder.build());
}
 
Example 7
Source File: AuthUI.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Set the {@link GoogleSignInOptions} to be used for Google sign-in. Standard
 * options like requesting the user's email will automatically be added.
 *
 * @param options sign-in options
 */
@NonNull
public GoogleBuilder setSignInOptions(@NonNull GoogleSignInOptions options) {
    Preconditions.checkUnset(getParams(),
            "Cannot overwrite previously set sign-in options.",
            ExtraConstants.GOOGLE_SIGN_IN_OPTIONS);

    GoogleSignInOptions.Builder builder = new GoogleSignInOptions.Builder(options);
    builder.requestEmail().requestIdToken(getApplicationContext()
            .getString(R.string.default_web_client_id));
    getParams().putParcelable(
            ExtraConstants.GOOGLE_SIGN_IN_OPTIONS, builder.build());

    return this;
}
 
Example 8
Source File: AuthUI.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Set the scopes that your app will request when using Google sign-in. See all <a
 * href="https://developers.google.com/identity/protocols/googlescopes">available
 * scopes</a>.
 *
 * @param scopes additional scopes to be requested
 */
@NonNull
public GoogleBuilder setScopes(@NonNull List<String> scopes) {
    GoogleSignInOptions.Builder builder =
            new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                    .requestEmail();
    for (String scope : scopes) {
        builder.requestScopes(new Scope(scope));
    }
    return setSignInOptions(builder.build());
}
 
Example 9
Source File: GoogleSignInHandler.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
private GoogleSignInOptions getSignInOptions() {
    GoogleSignInOptions.Builder builder = new GoogleSignInOptions.Builder(
            mConfig.getParams().<GoogleSignInOptions>getParcelable(
                    ExtraConstants.GOOGLE_SIGN_IN_OPTIONS));

    if (!TextUtils.isEmpty(mEmail)) {
        builder.setAccountName(mEmail);
    }

    return builder.build();
}
 
Example 10
Source File: MainActivity.java    From android-credentials with Apache License 2.0 5 votes vote down vote up
private void buildClients(String accountName) {
    GoogleSignInOptions.Builder gsoBuilder = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail();

    if (accountName != null) {
        gsoBuilder.setAccountName(accountName);
    }

    mCredentialsClient = Credentials.getClient(this);
    mSignInClient = GoogleSignIn.getClient(this, gsoBuilder.build());
}
 
Example 11
Source File: RxGoogleAuthFragment.java    From RxSocialAuth with Apache License 2.0 5 votes vote down vote up
private GoogleSignInOptions buildGoogleSignInOptions(Credential credential) {
    GoogleSignInOptions.Builder builder =
            new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN);

    if(mRequestEmail)
        builder.requestEmail();
    if(mRequestProfile)
        builder.requestProfile();
    if(mClientId != null)
        builder.requestIdToken(mClientId);
    if(credential != null)
        builder.setAccountName(credential.getId());

    return builder.build();
}
 
Example 12
Source File: AndroidGoogleAccount.java    From QtAndroidTools with MIT License 5 votes vote down vote up
private GoogleSignInClient getSignInClient(String ScopeName)
{
    GoogleSignInOptions.Builder SignInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN);
    if(ScopeName.isEmpty() == false) SignInOptions.requestScopes(new Scope(ScopeName));
    SignInOptions.requestEmail();

    return GoogleSignIn.getClient(mActivityInstance, SignInOptions.build());
}
 
Example 13
Source File: PlayGamesPlugin.java    From play_games with MIT License 5 votes vote down vote up
private void signIn(boolean requestEmail, boolean scopeSnapshot) {
    GoogleSignInOptions.Builder builder = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
    if (requestEmail) {
        builder.requestEmail();
    }
    if (scopeSnapshot) {
        builder.requestScopes(Drive.SCOPE_APPFOLDER);
    }
    GoogleSignInOptions opts = builder.build();
    GoogleSignInClient signInClient = GoogleSignIn.getClient(registrar.activity(), opts);
    silentSignIn(signInClient);
}
 
Example 14
Source File: GoogleSignUpActivity.java    From socialmediasignup with MIT License 5 votes vote down vote up
private void setupScopes(GoogleSignInOptions.Builder builder) {
    List<Scope> scopes = getScopes();
    if (scopes.size() == 1) {
        builder.requestScopes(scopes.get(0));
    } else if (scopes.size() > 1) {
        List<Scope> restScopes = scopes.subList(1, scopes.size());
        Scope[] restScopesArray = new Scope[restScopes.size()];
        restScopesArray = scopes.toArray(restScopesArray);
        builder.requestScopes(scopes.get(0), restScopesArray);
    }
}
 
Example 15
Source File: GoogleProviderHandler.java    From capacitor-firebase-auth with 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 16
Source File: PlayActivity.java    From firebase-android-client with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    ListView messageHistory;
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_play);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open,
            R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = findViewById(R.id.nav_view);
    channelMenu = navigationView.getMenu();
    navigationView.setNavigationItemSelectedListener(this);
    initChannels();

    GoogleSignInOptions.Builder gsoBuilder =
            new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                    .requestIdToken(getString(R.string.default_web_client_id))
                    .requestEmail();

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

    SignInButton signInButton = findViewById(R.id.sign_in_button);
    signInButton.setSize(SignInButton.SIZE_STANDARD);
    signInButton.setOnClickListener(this);
    channelLabel = findViewById(R.id.channelLabel);
    Button signOutButton = findViewById(R.id.sign_out_button);
    signOutButton.setOnClickListener(this);

    ImageButton microphoneButton = findViewById(R.id.microphone_button);
    microphoneButton.setOnClickListener(this);

    messages = new ArrayList<>();
    messageAdapter = new SimpleAdapter(this, messages, android.R.layout.simple_list_item_2,
            new String[]{"message", "meta"},
            new int[]{android.R.id.text1, android.R.id.text2});

    messageHistory = findViewById(R.id.messageHistory);
    messageHistory.setOnItemClickListener(this);
    messageHistory.setAdapter(messageAdapter);
    messageText = findViewById(R.id.messageText);
    messageText.setOnKeyListener(this);
    fmt = new SimpleDateFormat("yy.MM.dd HH:mm z", Locale.US);

    status = findViewById(R.id.status);
}
 
Example 17
Source File: GoogleHelper.java    From social-login-helper-Deprecated- with MIT License 4 votes vote down vote up
private GoogleSignInOptions buildSignInOptions(@Nullable String serverClientId) {
  GoogleSignInOptions.Builder gso =
      new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail();
  if (serverClientId != null) gso.requestIdToken(serverClientId);
  return gso.build();
}
 
Example 18
Source File: ConflictResolver.java    From android-samples with Apache License 2.0 4 votes vote down vote up
/**
 * Initiate the resolution process by connecting the GoogleApiClient.
 */
void resolve() {
    // [START drive_android_resolve_conflict]
    // A new DriveResourceClient should be created to handle each new CompletionEvent since each
    // event is tied to a specific user account. Any DriveFile action taken must be done using
    // the correct account.
    GoogleSignInOptions.Builder signInOptionsBuilder =
            new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                    .requestScopes(Drive.SCOPE_FILE)
                    .requestScopes(Drive.SCOPE_APPFOLDER);
    if (mConflictedCompletionEvent.getAccountName() != null) {
        signInOptionsBuilder.setAccountName(mConflictedCompletionEvent.getAccountName());
    }
    GoogleSignInClient signInClient =
            GoogleSignIn.getClient(mContext, signInOptionsBuilder.build());
    signInClient.silentSignIn()
            .continueWith(mExecutorService,
                    (Continuation<GoogleSignInAccount, Void>) signInTask -> {
                        mDriveResourceClient = Drive.getDriveResourceClient(
                                mContext, signInTask.getResult());
                        mBaseContent = ConflictUtil.getStringFromInputStream(
                                mConflictedCompletionEvent.getBaseContentsInputStream());
                        mModifiedContent = ConflictUtil.getStringFromInputStream(
                                mConflictedCompletionEvent
                                        .getModifiedContentsInputStream());
                        return null;
                    })
            .continueWithTask(mExecutorService,
                    task -> {
                        DriveId driveId = mConflictedCompletionEvent.getDriveId();
                        return mDriveResourceClient.openFile(
                                driveId.asDriveFile(), DriveFile.MODE_READ_ONLY);
                    })
            .continueWithTask(mExecutorService,
                    task -> {
                        mDriveContents = task.getResult();
                        InputStream serverInputStream = task.getResult().getInputStream();
                        mServerContent =
                                ConflictUtil.getStringFromInputStream(serverInputStream);
                        return mDriveResourceClient.reopenContentsForWrite(mDriveContents);
                    })
            .continueWithTask(mExecutorService,
                    task -> {
                        DriveContents contentsForWrite = task.getResult();
                        mResolvedContent = ConflictUtil.resolveConflict(
                                mBaseContent, mServerContent, mModifiedContent);

                        OutputStream outputStream = contentsForWrite.getOutputStream();
                        try (Writer writer = new OutputStreamWriter(outputStream)) {
                            writer.write(mResolvedContent);
                        }

                        // It is not likely that resolving a conflict will result in another
                        // conflict, but it can happen if the file changed again while this
                        // conflict was resolved. Since we already implemented conflict
                        // resolution and we never want to miss user data, we commit here
                        // with execution options in conflict-aware mode (otherwise we would
                        // overwrite server content).
                        ExecutionOptions executionOptions =
                                new ExecutionOptions.Builder()
                                        .setNotifyOnCompletion(true)
                                        .setConflictStrategy(
                                                ExecutionOptions
                                                        .CONFLICT_STRATEGY_KEEP_REMOTE)
                                        .build();

                        // Commit resolved contents.
                        MetadataChangeSet modifiedMetadataChangeSet =
                                mConflictedCompletionEvent.getModifiedMetadataChangeSet();
                        return mDriveResourceClient.commitContents(contentsForWrite,
                                modifiedMetadataChangeSet, executionOptions);
            })
            .addOnSuccessListener(aVoid -> {
                mConflictedCompletionEvent.dismiss();
                Log.d(TAG, "resolved list");
                sendResult(mModifiedContent);
            })
            .addOnFailureListener(e -> {
                // The contents cannot be reopened at this point, probably due to
                // connectivity, so by snoozing the event we will get it again later.
                Log.d(TAG, "Unable to write resolved content, snoozing completion event.",
                        e);
                mConflictedCompletionEvent.snooze();
                if (mDriveContents != null) {
                    mDriveResourceClient.discardContents(mDriveContents);
                }
            });
    // [END drive_android_resolve_conflict]
}