nick
nick

Reputation: 127

Create firebase auth from google auth token

I am using firebase google auth to manage users. Further, I have to integrate the users calendar using the calendar API, now firebase auth provides ID Token, ID Refresh token & oAuth token but not oAuth refresh token, due to which I will have to obtain the oAuth token & oAuth refresh token using gAPI, now I got that, but is there a way to use those tokens to create a firebase auth user? I know there is method to create sign in with signInWithCredential but this takes ID Token and not oAauth token.

UPDATE

Sign In code:

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);
});

After gAPI signin, I am getting following details:

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

Upvotes: 1

Views: 466

Answers (1)

Niraj Chauhan
Niraj Chauhan

Reputation: 7900

To access the ID Token, you have to add additional scope to the GAPI OAuth request. Along with your calendar scope, add "openid". Then in the token response, you should have access to id_token.

Also, you can skip the above step and exchange the OAuth token from google with firebase to get firebase ID Token.

Official docs: https://firebase.google.com/docs/reference/rest/auth/#section-sign-in-with-oauth-credential

Upvotes: 0

Related Questions