如何使用Firebase身份验证获取Google API的刷新令牌 [英] How to get refresh token for google api using Firebase authentication
问题描述
摘自Firebase文档
From firebase's documentation
firebase.auth().signInWithPopup(provider).then(function(result) {
// This gives you a Google Access Token. You can use it to access the
Google API.
var token = result.credential.accessToken;
// The signed-in user info.
var user = result.user;
// ...
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
// ...
});
无论如何,我可以使用Firebase身份验证获取Google api的刷新令牌.我在Firebase的文档中找不到有关此问题的任何信息.我也知道User
对象还包含refreshToken
.我可以使用firebase
中的refreshToken
为Google api生成一个新的access_token
吗?
Is there anyway I can get the refresh token for google api using firebase authentication. I couldn't find anything about this problem in Firebase's documentation. I am also aware that the User
object also contains a refreshToken
. Can I use that refreshToken
from firebase
to generate a new access_token
for google api ?
推荐答案
Firebase Auth当前专注于AuthN而不是AuthZ.它们不管理登录时的OAuth令牌.所有OAuth刷新令牌都将被丢弃,仅返回初始的OAuth访问令牌.如果您持续需要Google刷新令牌或Google访问令牌,请考虑使用
Firebase Auth is currently focused on AuthN and not AuthZ. They do not manage OAuth tokens on sign in. All OAuth refresh tokens are discarded and only the initial OAuth access token is returned. If you need a Google refresh token, or a Google access token continuously, consider using GApi
library to get a Google ID token/access token and then sign in with that to Firebase.
function onGoogleSignIn(googleUser) {
var googleIdToken = googleUser.getAuthResponse().id_token;
firebase.auth().signInWithCredential(
firebase.auth.GoogleAuthProvider.credential(googleIdToken));
}
您将始终能够以这种方式从Google登录库中获取Google OAuth访问令牌.
You will always have the ability to get a Google OAuth access token from the Google sign in library that way.
这篇关于如何使用Firebase身份验证获取Google API的刷新令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!