从Google身份验证令牌创建Firebase身份验证

BuCu开发

我正在使用Firebase Google Auth来管理用户。此外,我必须使用日历API集成用户日历,现在firebase auth提供了ID令牌,ID刷新令牌和oAuth令牌,但不提供oAuth刷新令牌,因此,我将不得不使用gAPI获得oAuth令牌和oAuth刷新令牌,现在我明白了,但是有没有办法使用这些令牌创建一个Firebase身份验证用户?我知道有创建登录的方法,signInWithCredential但这需要ID令牌而不是oAauth令牌。

更新

登录代码:

const { client_secret, client_id, redirect_uris } = credentials.web;
const oAuth2Client = new google.auth.OAuth2(client_id, client_secret, redirect_uris[0]);
const authUrl = oAuth2Client.generateAuthUrl({
    access_type: 'offline',
    scope: SCOPES,
});
// Get code from the URL


oAuth2Client.getToken(code, (err, token) => {
  oAuth2Client.setCredentials(token);
});

登录gAPI之后,我将获得以下详细信息:

{
    "access_token": "xxx",
    "refresh_token": "xxx",
    "scope": "https://www.googleapis.com/auth/calendar",
    "token_type": "Bearer",
    "expiry_date": 1613023105889
}
Niraj Chauhan

要访问ID令牌,您必须向GAPI OAuth请求中添加其他范围。与您的日历范围一起,添加“ openid”。然后,在令牌响应中,您应该可以访问id_token

另外,您可以跳过上述步骤,将Google的OAuth令牌与firebase交换,以获取firebase ID令牌。

官方文档:https : //firebase.google.com/docs/reference/rest/auth/#section-sign-in-with-oauth-credential

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章