How do I get the current user's access token in AngularFire2?

后端 未结 7 2195
星月不相逢
星月不相逢 2021-02-08 11:10

In AngularFire you were able to access the providers (e.g Google) accessToken for the authenticated user.

There does not seem to be a way to access this with AngularFire

7条回答
  •  广开言路
    2021-02-08 11:27

    The access token is only accessible when the user first signs in. From the Firebase migration guide for web developers:

    With the Firebase.com Authentication API, you can easily use the provider's access token to call out to the provider's API and get additional information. This access token is still available, but only immediately after the sign-in action has completed.

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

    So it is indeed not available on a page refresh. If you want it to remain available, you will need to persist it yourself.

提交回复
热议问题