从 google 授权令牌创建 firebase 授权

Create firebase auth from google auth token

我正在使用 firebase google 身份验证来管理用户。此外,我必须使用日历 API 集成用户日历,现在 firebase auth 提供 ID 令牌、ID 刷新令牌和 oAuth 令牌 , due to which I will have to obtain the oAuth token & oAuth refresh token using gAPI,现在我知道了,但是有没有办法使用这些用于创建 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
}

要访问 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