Java Code Examples for com.google.android.gms.auth.api.signin.GoogleSignInAccount#getIdToken()

The following examples show how to use com.google.android.gms.auth.api.signin.GoogleSignInAccount#getIdToken() . 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: GoogleLoginHiddenActivity.java    From SocialLoginManager with Apache License 2.0 6 votes vote down vote up
private void handleSignInResult(GoogleSignInResult result) {
  if (result.isSuccess()) {
    GoogleSignInAccount acct = result.getSignInAccount();
    SocialUser user = new SocialUser();
    user.userId = acct.getId();
    user.accessToken = acct.getIdToken();
    user.photoUrl = acct.getPhotoUrl() != null ? acct.getPhotoUrl().toString() : "";
    SocialUser.Profile profile = new SocialUser.Profile();
    profile.email = acct.getEmail();
    profile.name = acct.getDisplayName();
    user.profile = profile;
    SocialLoginManager.getInstance(this).onLoginSuccess(user);
  } else {
    Throwable throwable = new Throwable(result.getStatus().getStatusMessage());
    SocialLoginManager.getInstance(this).onLoginError(throwable);
  }

  finish();
}
 
Example 2
Source File: IdTokenActivity.java    From google-services with Apache License 2.0 6 votes vote down vote up
private void updateUI(@Nullable GoogleSignInAccount account) {
    if (account != null) {
        ((TextView) findViewById(R.id.status)).setText(R.string.signed_in);

        String idToken = account.getIdToken();
        mIdTokenTextView.setText(getString(R.string.id_token_fmt, idToken));

        findViewById(R.id.sign_in_button).setVisibility(View.GONE);
        findViewById(R.id.sign_out_and_disconnect).setVisibility(View.VISIBLE);
        mRefreshButton.setVisibility(View.VISIBLE);
    } else {
        ((TextView) findViewById(R.id.status)).setText(R.string.signed_out);
        mIdTokenTextView.setText(getString(R.string.id_token_fmt, "null"));

        findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
        findViewById(R.id.sign_out_and_disconnect).setVisibility(View.GONE);
        mRefreshButton.setVisibility(View.GONE);
    }
}
 
Example 3
Source File: GoogleProviderHandler.java    From capacitor-firebase-auth with MIT License 5 votes vote down vote up
@Override
public boolean isAuthenticated() {
    GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this.plugin.getContext());

    if (account != null) {
        String token = account.getIdToken();

        if (token == null) {
            Log.d(GOOGLE_TAG, "Google account found, but there is no token to check or refresh.");

            return false;
        } else {
            if (new JWT(token).isExpired(10)) {
                try {
                    Task<GoogleSignInAccount> task = this.mGoogleSignInClient.silentSignIn();
                    account = task.getResult(ApiException.class);
                    Log.d(GOOGLE_TAG, "Google silentSignIn succeed.");
                } catch (ApiException exception) {
                    Log.w(GOOGLE_TAG, String.format("Google silentSignIn failure: %s", exception.getLocalizedMessage()));

                    return false;
                }
            }
        }
    }


    return account != null;
}
 
Example 4
Source File: RxAccount.java    From RxSocialAuth with Apache License 2.0 5 votes vote down vote up
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 5
Source File: IdTokenActivity.java    From google-services with Apache License 2.0 5 votes vote down vote up
private void handleSignInResult(@NonNull Task<GoogleSignInAccount> completedTask) {
    try {
        GoogleSignInAccount account = completedTask.getResult(ApiException.class);
        String idToken = account.getIdToken();

        // TODO(developer): send ID Token to server and validate

        updateUI(account);
    } catch (ApiException e) {
        Log.w(TAG, "handleSignInResult:error", e);
        updateUI(null);
    }
}