- LAKSHAY's Newsletter
- Posts
- How Google OAuth works
How Google OAuth works

When we visit a website, we often use the Login with Google button to login or signup on the website. But have you ever wondered, how does the underlying technology of it works that allow us to login or signup on the website with just few clicks?
Let's understand how the underlying technology of Google OAuth works.
The process starts when the user clicks on the "Login with Google" button on the website, which redirects the user to the Google Authentication server.
After redirecting, Google presents you with the consent screen asking for the permission to share certain information with the website.
If you grant the permissions, you're redirected back to the original website with a authorization code in the website's URL.
After getting this authorization code, it is sent to the backend server of the application.
The server makes a request to get the Access Token and Refresh Token by providing the authorization code to the Google server. If the code is valid, we get both the tokens. ( Access and Refresh Token)
Refresh token allow websites to maintain the user's login status by obtaining new access token without requiring the user to re-authenticate, thus extending their session duration.
The server uses the access token to get the user information from the Google server.
After getting the user information, two things that can happen:
Login: The user information already exists in the database, so the user login on the website.
Signup: If user doesn't exist in our database, we create a entry for the user in our database and signup the user on the website.
The access token and refresh token are stored carefully in the backend server of the application.
This whole process works when we click on the Login with Google.

Google OAuth Working
I hope you liked the explanation of the working of the underlying technology of the Google OAuth.
Reply to this email with the topics you want me to cover in the upcoming newsletter. And what you liked about the explanation.
Thank you,
Lakshay Mahajan