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

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

问题描述



在AngularFire中,您可以访问提供者(例如Google)的accessToken。使用AngularFire2似乎没有办法访问



在初始登录时会这样说:

  this.af (用户){
console.log(user.google);
}
});

它将注销idToken,accessToken,provider,
但是(在页面刷新)随后会注销标准的细节(uid,displayName等....)
而accessToken不是一个可访问的属性?



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

解决方案

getToken 现在不推荐使用。您应该使用 getIdToken 代替:

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


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?

解决方案

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天全站免登陆