I am implementing Sign-in-with Google in my front end and using the token to validate my API calls in backend.
In Frontend, I implemented Sign in with Google like the following.
google.accounts.id.initialize({
client_id: "51....796-2b4...........8pv3.apps.googleusercontent.com",
callback: googleSigninCallback,
})
google.accounts.id.prompt() // Calling the prompt
In the above googleSigninCallback callback I am getting success response with the following object.
{
clientId: "3243287432...............",
client_id: "3243287432...............",
credential: "eyGudgs........dsfgh",
select_by: "user"
}
Using the above received credential I am able to validate the user in backend with the following code.
const { OAuth2Client } = require("google-auth-library");
const client = new OAuth2Client("51....796-2b4...........8pv3.apps.googleusercontent.com");
const ticket = await client.verifyIdToken({
idToken: "eyGudgs........dsfgh,
audience: "51....796-2b4...........8pv3.apps.googleusercontent.com",
});
Everything works fine in this flow.
But the problem is the above received credential will expire in one hour, So before that how can I get a new Token/ update the token so that the user can be kept logged in without asking for a One-Tap sign-in every time it expires?
I checked the documentation and couldn't find any answer anywhere. DOC: https://developers.google.com/identity/gsi/web/guides/overview