[英]How to get refresh token for google api using Firebase authentication
From firebase's documentation 从Firebase文档中
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;
// ...
});
Is there anyway I can get the refresh token for google api using firebase authentication. 无论如何,我可以使用Firebase身份验证获取Google api的刷新令牌。 I couldn't find anything about this problem in Firebase's documentation. 我在Firebase的文档中找不到有关此问题的任何信息。 I am also aware that the User
object also contains a refreshToken
. 我也知道User
对象还包含refreshToken
。 Can I use that refreshToken
from firebase
to generate a new access_token
for google api ? 我是否可以使用refreshToken
从firebase
来生成一个新access_token
为谷歌API?
Firebase Auth is currently focused on AuthN and not AuthZ. Firebase Auth当前专注于AuthN而不是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. 它们不管理登录时的OAuth令牌。所有OAuth刷新令牌都将被丢弃,仅返回初始的OAuth访问令牌。 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. 如果您持续需要Google刷新令牌或Google访问令牌,请考虑使用GApi
库获取Google ID令牌/访问令牌,然后使用该令牌登录Firebase。
function onGoogleSignIn(googleUser) {
var googleIdToken = googleUser.getAuthResponse().id_token;
firebase.auth().signInWithCredential(
firebase.auth.GoogleAuthProvider.credential(googleIdToken));
}
You will always have the ability to get a Google OAuth access token from the Google sign in library that way. 您将始终能够以这种方式从Google登录库中获取Google OAuth访问令牌。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.