我有一个 Firebase 应用程序,可以对用户进行身份验证并返回一个访问令牌,然后我可以使用该令牌来访问 Google Calendar 和 Sheets API。我还保存了刷新令牌。经过身份验证的令牌的示例代码:
firebase
.signInWithGoogle()
.then(async (socialAuthUser) => {
let accessToken = socialAuthUser.credential.accessToken // token to access Google Sheets API
let refreshToken = socialAuthUser.user.refreshToken
this.setState({accessToken, refreshToken})
})
Run Code Online (Sandbox Code Playgroud)
1 小时后,accessToken 将过期。Firebase 身份验证在登录后在用户对象上提供刷新令牌
我使用该刷新令牌重新进行身份验证并通过发布到以下位置获取新的 access_token:
https://securetoken.googleapis.com/v1/token?key=firebaseAppAPIKey
新的访问令牌不再适用于 Google API,并且不再具有授权范围。我也尝试将其发送到
https://www.googleapis.com/oauth2/v1/tokeninfo?access_token="refreshToken"
它给我错误“无效令牌”。当我使用 firebase 的原始令牌时,它工作得很好。
还有其他人遇到类似的问题吗?我还没有找到一种方法来使用正确的访问范围刷新原始访问令牌,而不需要用户注销并再次登录。
谢谢!
google-calendar-api google-api firebase google-drive-api google-oauth