I have implemented a google sign in button for my website using the steps outlined in this page:
https://developers.google.com/identity/sign-in/web/sign-in
The page then extracts the id_token and sends it to my backend server, which validates it against the Google validation endpoint. I then use their Google ID that is encoded in the id_token to retrieve the application specific data associated with it (stored on my database).
I'm just a bit confused on what I need to do next to keep the user "signed in" to my application and to continue to securely retrieve data from my backend API's.
I am intending to do the following:
- After I have validated the id_token I create a session ID for the user
- I store the session ID along with the users Google ID in a "sessions" table in my database
- I respond to the request by setting a cookie with the session ID
- For all subsequent requests I check the session ID in the cookie
- If there is an entry for that session ID in the sessions table, I use the Google ID associated with it to retrieve the users info
I would just like to know if this sounds reasonable, is it best practice or if there is a better way to do this? Is there are secure way to generate session ID's or are there API's to help with this (I am currently using ASP.Net Web Api 2 for my backend services)
Many thanks,
I think you're confusing authentication and authorization. You should have your own record of the user in your server app and the key is Google, not the "name". Here's what I do in my Django (Python) application:
Note. Django handles all the authorization from this point onwards. Google was just there to handle the authentication that proves to me that he/she owns that email address.