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

Intellidroid picture Intellidroid · Oct 14, 2016 · Viewed 8.4k times · Source

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 AngularFire2?

On initial login say like this:

this.af.auth.subscribe(user=> {
  if (user) {
    console.log(user.google);
  }
});

It will log out the idToken, accessToken, provider, But (on a page refresh) subsequently will log out the standard details (uid, displayName etc....) And the accessToken is not an accessible property?

Is there a way to access the current users accessToken?

Answer

Will picture Will · Jun 29, 2017

getToken is deprecated now. You should use getIdToken instead:

this.af.auth.currentUser.getIdToken(true)
  .then((token) => localStorage.setItem('tokenId', token));