简体   繁体   English

如何使用Firebase身份验证获取Google API的刷新令牌

[英]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 ? 我是否可以使用refreshTokenfirebase来生成一个新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.

相关问题 如何使用Firebase刷新令牌保留用户身份验证? - How do I persist user authentication using the Firebase refresh token? REST API 与 Google Firebase 身份验证和使用不记名令牌的函数 - REST API with Google Firebase Authentication & Functions using Bearer Token 如何获得一个新的访问令牌以与 Google Api 进行交互,并以 angular 进行 Firebase 身份验证? - how to get a new acces token to interact with Google Api with firebase authentication in angular? React Native 中的 Firebase Rest API 身份验证 ID 令牌和令牌刷新 - Firebase Rest API Authentication ID Token and Token Refresh in React Native 1小时后如何使用firebase身份验证获取新的访问令牌和刷新令牌 - how to Get new access token and refresh token after 1 hour with firebase authentication 如何获取访问令牌以使用Firebase在Google API中注册iOS设备 - How to get the access token to register iOS device in Google API with Firebase 如何使用 Firebase 刷新令牌来保持身份验证? - How do I use a Firebase refresh token to persist authentication? Firebase 身份验证:无法使用刷新令牌获取新令牌 REST - Firebase Auth: Can not get a new token using refresh token REST 使用令牌进行Firebase身份验证 - Firebase authentication using token 将 Google 身份验证令牌与 Firebase 结合使用 - Use Google authentication token with Firebase
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM