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

其他-如何获得一个新的acces令牌,以便通过 Angular 的Firebase身份验证与Google Api进行交互?

(其他 - how to get a new acces token to interact with Google Api with firebase authentication in angular?)

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

用户通过firebasebase提供程序登录到我的angular应用程序。

new firebase.auth.GoogleAuthProvider()

依次

firebase.auth().getRedirectResult()

当应用程序访问时,我只有一个令牌,例如

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

不久后就会过期。正如Google官方文档所述,我如何增加截止时间

更新

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;
});

我想得到这个,token但有效期延长

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

解决方案:

步骤1
我已经在我的 Angular 项目中安装了ng-gapi(并对其进行配置)

第2步
通过谷歌ng-gapi我登录

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

第3步
我按照文档所述以Firebase手动登录

第4步
现在通过ng-gapi我可以获得令牌

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

(我不知道是否存在要获取的poper函数,x.Od.$B但它可以正常工作)