简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM