Automatic (new) sign in with Google / stay signed in - web app

Viewed 445

TLDR: I've been struggling with the new Sign in with Google functionality and especially the part how I can let the user stay signed in. What I understand from the docs is that Google only tells "this is a user who would like to sign in" but basically I would still need to create my own backend to track that user.

Note this question is about the new Sign in with Google functionality, all the guides/questions I can seem to find are about legacy sign-in and this is quite well described here: https://developers.google.com/identity/sign-in/web/server-side-flow

What confuses me most is basically already stated in the beginning of the guide: https://developers.google.com/identity/gsi/web/guides/overview?hl=en#user_sign-in_to_your_site

You'll manage per user session state for sign-in to your site.

User sign-in status to their Google Account and your app are independent of each other, except during the sign-in moment itself when you know that the user has successfully authenticated and is signed into their Google Account. Users may remain signed-in, sign-out, or switch to a different Google Account while maintaining an active, signed-in session on your website.

I understand the basic principle behind OAuth and the part where you have to exchange the authorization code for an access token and you can verify this access token (which is perfectly described in the legacy guide), but this is now only required for OAuth2 in order to access personal data. If I understand correctly this access token can be used as an identifier for a specific session (as alternative to a password or session cookie).

With the new sign in policy you will only get a JWT which identifies the user. Also apparently the only way to get a JWT is as a response when the user clicks the Sign in with Google button and selects the account in the consent screen (which ideally should only occur once).

What I actually want to achieve is that when a user enters the site I want to send a request "Hey Google this user is visiting my site, do you recognize this session and is it still valid".

Maybe I'm thinking way too difficult, but what I just don't understand is how can the new Google Login actually help me remember and validate users?

1 Answers

After some more digging around I found a lead on this page: https://developers.google.com/identity/gsi/web/guides/migration#object_migration_reference_for_user_sign-in

Basically what I am looking for was provided by the depreciated GoogleAuth.isSignedIn.get() function, but the notes clearly show:

Remove. A user's current sign-in status on Google is unavailable. Users must be signed-in to Google for consent and sign-in moments.

Combined with the prior statement:

You'll manage per user session state for sign-in to your site.

To validate the assumption I did some testing with other web services where I logged in using Google, revoked the log-in access for that website from the Google console and when revisiting that website I was still logged in to the website.

My conclusion: Google login only verifies the initial login Google basically responds with "Yes this is a valid user" I have to keep track of the user session using cookies/databases myself

Related