Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Google access token

To get Google access token after firebase auth login, I know I can simply do this:

    firebase.auth().signInWithPopup(provider).then(function(result) {
      var token = result.credential.accessToken;
}

but what if the user is already authenticated and I need the token? is there any way to extract it from the Firebase auth?

I've been through every value of authState but I couldn't find the google access token I've been looking for.

like image 646
TheUnreal Avatar asked Jun 11 '17 13:06

TheUnreal


People also ask

How do I find the access token in Google Sheets?

Obtaining Access Token and Refresh TokenNavigate to OAuth 2.0 Playground and click the OAuth 2.0 Configuration button in the top right corner of your screen. Select Use your own OAuth credentials, and provide the obtained Client ID and Client Secret values. Click on Close.

How do I find my access token?

The high-level overview of validating an access token looks like this: Retrieve and parse your Okta JSON Web Keys (JWK), which should be checked periodically and cached by your application. Decode the access token, which is in JSON Web Token format. Verify the signature used to sign the access token.


1 Answers

You can't get the access token from the onAuthStateChanged listener or the currentUser. You can only get it immediately after authentication when calling signInWithPopup, reauthenticateWithPopup, linkWithPopup, getRedirectResult, etc. Firebase Auth does not manage OAuth tokens for users. If you feel strongly about this feature, please file a feature request for it on the Firebase forum: https://groups.google.com/forum/#!forum/firebase-talk

You can also just use the GApi library to get the Google access token and pass it to Firebase to sign-in via signInWithCredential. The advantage here is that GApi will manage that OAuth token for you.

like image 191
bojeil Avatar answered Oct 19 '22 08:10

bojeil