如何在 AngularFire2 中获取当前用户的访问令牌? [英] How do I get the current user's access token in AngularFire2?

查看:29
本文介绍了如何在 AngularFire2 中获取当前用户的访问令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 AngularFire 中,您可以为经过身份验证的用户访问提供程序(例如 Google)的 accessToken.

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

似乎没有办法使用 AngularFire2 访问它?

There does not seem to be a way to access this with AngularFire2?

在初次登录时这样说:

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

它会注销 idToken、accessToken、provider、但是(在页面刷新时)随后将注销标准详细信息(uid、displayName 等....)而且 accessToken 不是可访问的属性?

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?

有没有办法访问当前用户的accessToken?

Is there a way to access the current users accessToken?

推荐答案

getToken 现已弃用.您应该使用 getIdToken 代替:

getToken is deprecated now. You should use getIdToken instead:

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

这篇关于如何在 AngularFire2 中获取当前用户的访问令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆