com.google.android.gms.auth.api.credentials.IdentityProviders Java Examples
The following examples show how to use
com.google.android.gms.auth.api.credentials.IdentityProviders.
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: MainActivity.java From identity-samples with Apache License 2.0 | 6 votes |
/** * Called when the Load Hints button is clicked. Requests a Credential "hint" which will * be the basic profile information and an ID token for an account on the device. This is useful * to auto-fill sign-up forms with an email address, picture, and name or to do password-free * authentication with a server by providing an ID Token. */ private void loadHintClicked() { HintRequest hintRequest = new HintRequest.Builder() .setHintPickerConfig(new CredentialPickerConfig.Builder() .setShowCancelButton(true) .build()) .setIdTokenRequested(shouldRequestIdToken()) .setEmailAddressIdentifierSupported(true) .setAccountTypes(IdentityProviders.GOOGLE) .build(); ; PendingIntent intent = mCredentialsClient.getHintPickerIntent(hintRequest); try { startIntentSenderForResult(intent.getIntentSender(), RC_HINT, null, 0, 0, 0); mIsResolving = true; } catch (IntentSender.SendIntentException e) { Log.e(TAG, "Could not start hint picker Intent", e); mIsResolving = false; } }
Example #2
Source File: MainActivity.java From journaldev with MIT License | 6 votes |
public void showHintDialog() { HintRequest hintRequest = new HintRequest.Builder() .setHintPickerConfig(new CredentialPickerConfig.Builder() .setShowCancelButton(true) .build()) .setEmailAddressIdentifierSupported(true) .setAccountTypes(IdentityProviders.GOOGLE, IdentityProviders.FACEBOOK) .build(); PendingIntent intent = mCredentialsApiClient.getHintPickerIntent(hintRequest); try { startIntentSenderForResult(intent.getIntentSender(), RC_HINT, null, 0, 0, 0); } catch (IntentSender.SendIntentException e) { Log.e(TAG, "Could not start hint picker Intent", e); } }
Example #3
Source File: MainActivity.java From android-credentials with Apache License 2.0 | 6 votes |
/** * Called when the Load Hints button is clicked. Requests a Credential "hint" which will * be the basic profile information and an ID token for an account on the device. This is useful * to auto-fill sign-up forms with an email address, picture, and name or to do password-free * authentication with a server by providing an ID Token. */ private void loadHintClicked() { HintRequest hintRequest = new HintRequest.Builder() .setHintPickerConfig(new CredentialPickerConfig.Builder() .setShowCancelButton(true) .build()) .setIdTokenRequested(shouldRequestIdToken()) .setEmailAddressIdentifierSupported(true) .setAccountTypes(IdentityProviders.GOOGLE) .build(); ; PendingIntent intent = mCredentialsClient.getHintPickerIntent(hintRequest); try { startIntentSenderForResult(intent.getIntentSender(), RC_HINT, null, 0, 0, 0); mIsResolving = true; } catch (IntentSender.SendIntentException e) { Log.e(TAG, "Could not start hint picker Intent", e); mIsResolving = false; } }
Example #4
Source File: ProviderUtils.java From FirebaseUI-Android with Apache License 2.0 | 6 votes |
/** * Translate a Firebase Auth provider ID (such as {@link GoogleAuthProvider#PROVIDER_ID}) to a * Credentials API account type (such as {@link IdentityProviders#GOOGLE}). */ public static String providerIdToAccountType( @AuthUI.SupportedProvider @NonNull String providerId) { switch (providerId) { case GoogleAuthProvider.PROVIDER_ID: return IdentityProviders.GOOGLE; case FacebookAuthProvider.PROVIDER_ID: return IdentityProviders.FACEBOOK; case TwitterAuthProvider.PROVIDER_ID: return IdentityProviders.TWITTER; case GithubAuthProvider.PROVIDER_ID: return GITHUB_IDENTITY; case PhoneAuthProvider.PROVIDER_ID: return PHONE_IDENTITY; // The account type for email/password creds is null case EmailAuthProvider.PROVIDER_ID: default: return null; } }
Example #5
Source File: ProviderUtils.java From FirebaseUI-Android with Apache License 2.0 | 6 votes |
@AuthUI.SupportedProvider public static String accountTypeToProviderId(@NonNull String accountType) { switch (accountType) { case IdentityProviders.GOOGLE: return GoogleAuthProvider.PROVIDER_ID; case IdentityProviders.FACEBOOK: return FacebookAuthProvider.PROVIDER_ID; case IdentityProviders.TWITTER: return TwitterAuthProvider.PROVIDER_ID; case GITHUB_IDENTITY: return GithubAuthProvider.PROVIDER_ID; case PHONE_IDENTITY: return PhoneAuthProvider.PROVIDER_ID; default: return null; } }
Example #6
Source File: MainActivity.java From identity-samples with Apache License 2.0 | 5 votes |
private void handleCredential(Credential credential) { mCredential = credential; Log.d(TAG, "handleCredential:" + credential.getAccountType() + ":" + credential.getId()); if (IdentityProviders.GOOGLE.equals(credential.getAccountType())) { // Google account, rebuild GoogleApiClient to set account name and then try buildClients(credential.getId()); googleSilentSignIn(); } else { // Email/password account String status = String.format("Signed in as %s", credential.getId()); ((TextView) findViewById(R.id.text_email_status)).setText(status); } }
Example #7
Source File: MainActivity.java From identity-samples with Apache License 2.0 | 5 votes |
private void handleGoogleSignIn(Task<GoogleSignInAccount> completedTask) { Log.d(TAG, "handleGoogleSignIn:" + completedTask); boolean isSignedIn = (completedTask != null) && completedTask.isSuccessful(); if (isSignedIn) { // Display signed-in UI GoogleSignInAccount gsa = completedTask.getResult(); String status = String.format("Signed in as %s (%s)", gsa.getDisplayName(), gsa.getEmail()); ((TextView) findViewById(R.id.text_google_status)).setText(status); // Save Google Sign In to SmartLock Credential credential = new Credential.Builder(gsa.getEmail()) .setAccountType(IdentityProviders.GOOGLE) .setName(gsa.getDisplayName()) .setProfilePictureUri(gsa.getPhotoUrl()) .build(); saveCredential(credential); } else { // Display signed-out UI ((TextView) findViewById(R.id.text_google_status)).setText(R.string.signed_out); } findViewById(R.id.button_google_sign_in).setEnabled(!isSignedIn); findViewById(R.id.button_google_sign_out).setEnabled(isSignedIn); findViewById(R.id.button_google_revoke).setEnabled(isSignedIn); }
Example #8
Source File: MainActivity.java From identity-samples with Apache License 2.0 | 5 votes |
private void requestCredentials(final boolean shouldResolve, boolean onlyPasswords) { CredentialRequest.Builder crBuilder = new CredentialRequest.Builder() .setPasswordLoginSupported(true); if (!onlyPasswords) { crBuilder.setAccountTypes(IdentityProviders.GOOGLE); } showProgress(); mCredentialsClient.request(crBuilder.build()).addOnCompleteListener( new OnCompleteListener<CredentialRequestResponse>() { @Override public void onComplete(@NonNull Task<CredentialRequestResponse> task) { hideProgress(); if (task.isSuccessful()) { // Auto sign-in success handleCredential(task.getResult().getCredential()); return; } Exception e = task.getException(); if (e instanceof ResolvableApiException && shouldResolve) { // Getting credential needs to show some UI, start resolution ResolvableApiException rae = (ResolvableApiException) e; resolveResult(rae, RC_CREDENTIALS_READ); } else { Log.w(TAG, "request: not handling exception", e); } } }); }
Example #9
Source File: RxAccount.java From RxSocialAuth with Apache License 2.0 | 5 votes |
public RxAccount(GoogleSignInAccount gsa) { this.id = gsa.getId(); this.accessToken = gsa.getIdToken(); this.email = gsa.getEmail(); this.firstname = gsa.getGivenName(); this.lastname = gsa.getFamilyName(); this.displayName = gsa.getDisplayName(); this.photoUri = gsa.getPhotoUrl(); this.provider = IdentityProviders.GOOGLE; }
Example #10
Source File: MainActivity.java From android-credentials with Apache License 2.0 | 5 votes |
private void handleCredential(Credential credential) { mCredential = credential; Log.d(TAG, "handleCredential:" + credential.getAccountType() + ":" + credential.getId()); if (IdentityProviders.GOOGLE.equals(credential.getAccountType())) { // Google account, rebuild GoogleApiClient to set account name and then try buildClients(credential.getId()); googleSilentSignIn(); } else { // Email/password account String status = String.format("Signed in as %s", credential.getId()); ((TextView) findViewById(R.id.text_email_status)).setText(status); } }
Example #11
Source File: MainActivity.java From android-credentials with Apache License 2.0 | 5 votes |
private void handleGoogleSignIn(Task<GoogleSignInAccount> completedTask) { Log.d(TAG, "handleGoogleSignIn:" + completedTask); boolean isSignedIn = (completedTask != null) && completedTask.isSuccessful(); if (isSignedIn) { // Display signed-in UI GoogleSignInAccount gsa = completedTask.getResult(); String status = String.format("Signed in as %s (%s)", gsa.getDisplayName(), gsa.getEmail()); ((TextView) findViewById(R.id.text_google_status)).setText(status); // Save Google Sign In to SmartLock Credential credential = new Credential.Builder(gsa.getEmail()) .setAccountType(IdentityProviders.GOOGLE) .setName(gsa.getDisplayName()) .setProfilePictureUri(gsa.getPhotoUrl()) .build(); saveCredential(credential); } else { // Display signed-out UI ((TextView) findViewById(R.id.text_google_status)).setText(R.string.signed_out); } findViewById(R.id.button_google_sign_in).setEnabled(!isSignedIn); findViewById(R.id.button_google_sign_out).setEnabled(isSignedIn); findViewById(R.id.button_google_revoke).setEnabled(isSignedIn); }
Example #12
Source File: MainActivity.java From android-credentials with Apache License 2.0 | 5 votes |
private void requestCredentials(final boolean shouldResolve, boolean onlyPasswords) { CredentialRequest.Builder crBuilder = new CredentialRequest.Builder() .setPasswordLoginSupported(true); if (!onlyPasswords) { crBuilder.setAccountTypes(IdentityProviders.GOOGLE); } showProgress(); mCredentialsClient.request(crBuilder.build()).addOnCompleteListener( new OnCompleteListener<CredentialRequestResponse>() { @Override public void onComplete(@NonNull Task<CredentialRequestResponse> task) { hideProgress(); if (task.isSuccessful()) { // Auto sign-in success handleCredential(task.getResult().getCredential()); return; } Exception e = task.getException(); if (e instanceof ResolvableApiException && shouldResolve) { // Getting credential needs to show some UI, start resolution ResolvableApiException rae = (ResolvableApiException) e; resolveResult(rae, RC_CREDENTIALS_READ); } else { Log.w(TAG, "request: not handling exception", e); } } }); }
Example #13
Source File: AuthActivity.java From RxSocialAuth with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_auth); // butter knife ButterKnife.bind(this); // request smart lock credential on launch new RxSmartLockPasswords.Builder(this) .disableAutoSignIn() .setAccountTypes(IdentityProviders.GOOGLE, IdentityProviders.FACEBOOK) .build() .requestCredentialAndAutoSignIn() .subscribe(o -> { if(o instanceof RxAccount) { // user is signed in using google or facebook RxAccount rxAccount = (RxAccount) o; // log info Log.d(TAG, "provider: " + rxAccount.getProvider()); Log.d(TAG, "userId: " + rxAccount.getId()); Log.d(TAG, "photoUrl: " + (rxAccount.getPhotoUri() != null? rxAccount.getPhotoUri().toString(): "")); Log.d(TAG, "accessToken: " + rxAccount.getAccessToken()); Log.d(TAG, "firstname: " + rxAccount.getFirstname()); Log.d(TAG, "lastname: " + rxAccount.getLastname()); Log.d(TAG, "name: " + rxAccount.getDisplayName()); Log.d(TAG, "email: " + rxAccount.getEmail()); Toast.makeText(AuthActivity.this, "Hello " + rxAccount.getDisplayName(), Toast.LENGTH_SHORT).show(); // go to main activity startActivity(new Intent(AuthActivity.this, MainActivity.class)); finish(); } else if(o instanceof Credential) { Credential credential = (Credential) o; if(credential.getAccountType() == null) { // credential contains login and password signInWithLoginPassword(credential.getId(), credential.getPassword()); } else { // credential from other provider than Google or Facebook handleCredential(credential); } } }, throwable -> { Log.e(TAG, throwable.getMessage()); }); }
Example #14
Source File: RxSmartLockPasswords.java From RxSocialAuth with Apache License 2.0 | 4 votes |
public Builder(FragmentActivity activity) { this.activity = activity; credentialRequestBuilder = new CredentialRequest.Builder(); // at least one provider (mandatory) credentialRequestBuilder.setAccountTypes(IdentityProviders.GOOGLE); }
Example #15
Source File: MainActivity.java From journaldev with MIT License | 4 votes |
public void createCredentialRequest() { mCredentialRequest = new CredentialRequest.Builder() .setPasswordLoginSupported(true) .setAccountTypes(IdentityProviders.GOOGLE) .build(); }