Warm tip: This article is reproduced from serverfault.com, please click

how to get a new acces token to interact with Google Api with firebase authentication in angular?

发布于 2020-11-22 22:00:35

users log into my angular application via firebasebase provider.

new firebase.auth.GoogleAuthProvider()

successively

firebase.auth().getRedirectResult()

When the application accesses I only have a token like

ya29.a0AfH6SMAYg1A1RLwrEGe19qozweR9AFXuLJwSHb4FzQvuXk-ObVa54mpErd09mb4G3***********

that expires after a short time. How do I increase the deadline time as the official google documentation says?

Update

firebase.auth().getRedirectResult().then(function(result) {

 if (result.credential) {
    // This gives you a Google Access Token.
    var token = result.credential.accessToken;
  }
  var user = result.user;
});

I would like to get this token but with extended expiration

Questioner
Edoardo
Viewed
0
Edoardo 2020-11-28 20:30:17

SOLUTION:

Step 1:
i have installed ng-gapi in my angular project. (and configured it)

Step 2:
through google ng-gapi i logged in

 this.gapiService.getAuth()
  .subscribe((auth) => {
    auth.signIn().then(res => this.signInSuccessHandler(res));
  });

Step 3:
i login in firebase mannualy as documentation said

Step 4:
now through ng-gapi i can get the token

this.gapiService.getAuth().subscribe(x => {
  console.log(x.Od.$B);
});

(i don't know if exist a poper function to get x.Od.$B but it's work)