Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 778
Intellidroid Avatar asked Oct 14 '16 11:10

Intellidroid


People also ask

Where is the firebase token?

The token should be saved inside your systems data-store and should be easily accessible when required. The examples below use a Cloud Firestore database to store and manage the tokens, and Firebase Authentication to manage the users identity. You can however use any datastore or authentication method of your choice.

What is firebase access token?

Firebase ID tokens When a user or device signs in using Firebase Authentication, Firebase creates a corresponding ID token that uniquely identifies them and grants them access to several resources, such as Realtime Database and Cloud Storage.

What is firebase Authentication code?

The Firebase Authentication SDK provides methods to create and manage users that use their email addresses and passwords to sign in. Firebase Authentication also handles sending password reset emails. iOS Android Web C++ Unity. Federated identity provider integration.


1 Answers

With AngularFire2, you can get the token like this :

this.af.auth.getToken() // returns a firebase.Promise<any>

If you want to get an ES6 Promise instead, just use

Promise.resolve()
  .then(() => this.af.auth.getToken() as Promise<string>)
like image 143
Julien Boulay Avatar answered Oct 01 '22 17:10

Julien Boulay