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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With