使用Firebase身份验证重新加载页面后获取Youtube访问令牌

时间:2017-05-03 19:53:46

标签: firebase youtube-api firebase-authentication

我希望用户在通过Firebase登录Google后可以访问他们的Youtube播放列表。我使用firebase.auth().signInWithRedirect(provider)进行登录,我可以使用firebase.auth().getRedirectResult()获取访问令牌,一切都在他们登录后完美运行。

问题是,如果他们刷新页面,我就无法获得他们的访问令牌。 Firebase会自动重新登录,但firebase.auth().getRedirectResult()会返回

{user: null, credential: undefined, operationType: undefined}

我已尝试使用Google OAuth 2.0 Playground中使用的方法,但我不知道从哪里获取步骤2中使用的授权码。

我很感激你的帮助。

1 个答案:

答案 0 :(得分:1)

Firebase无法提供刷新Google访问令牌的方法。也许您最好使用Google网络登录SDK来获取Google访问令牌:https://developers.google.com/identity/sign-in/web/sign-in 它还会自动为您刷新。 然后,您可以传递Google访问令牌或ID令牌以使用Firebase登录:

firebase.auth().signInWithCredential(firebase.auth.GoogleAuthProvider.credential(googleIdToken, googleAccessToken));