OAuth2 using Google Auth - Node.Js, VueJs

Introduction Bonjour! Welcome to the first article in the series: "OAuth2 Authentication for APIs". Our starting point is integrating Google OAuth2 with a Vue.js frontend and a Node.js backend. The end goal of this series is to create a modular authentication system that can support multiple providers. What is OAuth2? Rather than reinvent the wheel, here are some excellent resources that cover OAuth2 in detail: What is OAuth 2.0? Thus, these are the main concepts: Client: The frontend application that wants access to user data from Google. Backend Engine: This is the server-side application that has all the business logic. Authorization Server: This is a google server that issues access and a refresh token to the Client application. Resource server: This is google server that validates whether an access token is valid. OAuth2 Flow Overview From the image above, view the following steps: The frontend requests Google login. User is redirected to Google to log in. Google returns an authorization code. Frontend sends the code to the backend. Backend exchanges the code for tokens. Backend verifies the ID token and extracts user info. Backend issues its own JWT to the frontend. Frontend stores JWT for API calls. Backend handles access token refresh when needed. The following are the steps I performed to make this project a success: Create a Google client ID and client secret. Create a Frontend client Create a backend application Connecting everything Configuration on Google Cloud Console

Apr 6, 2025 - 20:54
 0
OAuth2 using Google Auth - Node.Js, VueJs

Introduction

Bonjour! Welcome to the first article in the series: "OAuth2 Authentication for APIs". Our starting point is integrating Google OAuth2 with a Vue.js frontend and a Node.js backend. The end goal of this series is to create a modular authentication system that can support multiple providers.

What is OAuth2?

Rather than reinvent the wheel, here are some excellent resources that cover OAuth2 in detail:

Thus, these are the main concepts:

  • Client: The frontend application that wants access to user data from Google.
  • Backend Engine: This is the server-side application that has all the business logic.
  • Authorization Server: This is a google server that issues access and a refresh token to the Client application.
  • Resource server: This is google server that validates whether an access token is valid.

OAuth2 Flow Overview

Image description
From the image above, view the following steps:

  1. The frontend requests Google login.
  2. User is redirected to Google to log in.
  3. Google returns an authorization code.
  4. Frontend sends the code to the backend.
  5. Backend exchanges the code for tokens.
  6. Backend verifies the ID token and extracts user info.
  7. Backend issues its own JWT to the frontend.
  8. Frontend stores JWT for API calls.
  9. Backend handles access token refresh when needed.

The following are the steps I performed to make this project a success:

  • Create a Google client ID and client secret.
  • Create a Frontend client
  • Create a backend application
  • Connecting everything

Configuration on Google Cloud Console