I am developing a Sinatra web app to which I plan to add a Google sign in capability.
While I am able to understand the Oauth2 authentication mechanism with Google and everything seems to work fine, I have a basic question on maintaining sessions. I am using the Server side web application flow of Oauth2.
Before I ask my question here is my understanding of the Oauth2 authentication mechanism.
Once the user clicks on the "Sign in with Google" button, the sequence of events are:
- The user is redirected to the Google oauth authorization server.
- The Google oauth2 authorization server checks if the user has a active session.
- If yes it prompts the user to grant access to my application for the requested data from Google.
- If the user grants access then the process of sending back an auth_code and getting access tokens commences.
Based on what I have encountered on the web, the code for all of the above would have to be put in a before filter.
My questions are below:
- If I add this code to a before filter, then there would be a round trip to the Google Authentication server for each request that comes to my application from the user.
- Am I thinking right in the statement 1 above?
- Is this necessary?
- Is there some other way of validating session without reaching out to the Google server for each request to my server?
- Will this not cause an overhead?
- How do web-apps using oauth2 typically handle checking session validity across multiple requests?
Sorry about the longish question and thanks for your patience.