获取Google访问令牌

The*_*eal 8 firebase gapi firebase-authentication

要在firebase auth登录后获取Google访问令牌,我知道我可以这样做:

    firebase.auth().signInWithPopup(provider).then(function(result) {
      var token = result.credential.accessToken;
}
Run Code Online (Sandbox Code Playgroud)

但是,如果用户已经过身份验证并且我需要令牌呢?有没有办法从Firebase auth中提取它?

我已经完成了所有的价值,authState但我找不到我一直在寻找的谷歌访问令牌.

boj*_*eil 10

您无法从onAuthStateChanged侦听器或其中获取访问令牌currentUser.打电话时您只能立即得到它在身份验证之后signInWithPopup,reauthenticateWithPopup,linkWithPopup,getRedirectResult,等火力地堡验证没有为用户管理OAuth凭证.如果您对此功能有强烈的兴趣,请在Firebase论坛上提交功能请求:https://groups.google.com/forum/#!forum/firebase-talk

您也可以使用GApi库获取Google访问令牌,并将其传递给Firebase以通过登录进行登录signInWithCredential.这里的优点是GApi将为您管理该OAuth令牌.

  • 您不能只传递一个普通的ID令牌,您必须将其包装在凭证中.`signInWithCredential(firebase.auth.GoogleAuthProvider.credential(令牌))` (3认同)