Google OAuth Authentication
The complete source of the following example plugin can be found here: example-plugins/google-auth-plugin
Google OAuth authentication allows customers to sign in using their Google accounts, providing a seamless experience that eliminates the need for password-based registration.
This is particularly valuable for consumer-facing stores where users prefer the convenience and security of Google's authentication system, or for B2B platforms where organizations use Google Workspace.
This guide shows you how to add Google OAuth support to your Vendure store using a custom AuthenticationStrategy and Google Identity Services.
An AuthenticationStrategy in Vendure defines how users can log in to your store. Learn more about authentication in Vendure.
Creating the Plugin
First, use the Vendure CLI to create a new plugin for Google authentication:
This creates a basic plugin structure with the necessary files.
Installing Dependencies
Google authentication requires the Google Auth Library for token verification:
This library handles ID token verification securely on the server side, ensuring the tokens received from Google are authentic.
Creating the Authentication Strategy
Now create the Google authentication strategy. Unlike traditional OAuth flows that use authorization codes, Google Identity Services provides ID tokens directly, which we verify server-side:
The strategy uses Google's OAuth2Client to verify ID tokens and Vendure's ExternalAuthenticationService to handle customer creation.
Key differences from other OAuth flows:
- ID Token Verification: Google provides signed JWT tokens that we verify directly
- No Code Exchange: Unlike GitHub OAuth, there's no authorization code to exchange
- Email Verification: We respect Google's email verification status
- Fallback Names: Provides defaults if Google profile lacks name information
Registering the Strategy
Now update the generated plugin file to register your authentication strategy:
Adding to Vendure Config
Add the plugin to your Vendure configuration:
Setting up Google OAuth App
Before you can test the integration, you need to create a Google OAuth 2.0 Client:
- Go to the Google Cloud Console
- Create a new project or select an existing one
- Navigate to APIs & Services → Credentials
- Click "Create Credentials" → "OAuth 2.0 Client ID"
- Select "Web application" as the application type
- Configure the client:
- Name: Your app name (e.g., "My Vendure Store")
- Authorized JavaScript origins:
http://localhost:3001 - Authorized redirect URIs:
http://localhost:3001/sign-in
The localhost URLs shown here are for local development only. In production, replace localhost:3001 with your actual domain (e.g., https://mystore.com).
- Click "Create" and copy the Client ID
Add the client ID to your environment:
Frontend Integration
Creating the Sign-in Component
For the frontend, we'll use Google's official Identity Services library, which provides a secure and user-friendly sign-in experience:
Creating the Authentication Function
Create a server action to handle the Google authentication:
Add your Google Client ID to the frontend environment:
The Google Identity Services flow works as follows:
- User clicks "Continue with Google" → Google popup appears
- User signs in with Google → Google returns an ID token
- Frontend sends the token to Vendure → Vendure verifies token with Google
- If valid, Vendure creates/finds customer → User is logged in
Using the GraphQL API
Once your plugin is running, Google authentication will be available in your shop API:
Customer Data Management
Google-authenticated customers are managed like any other Vendure Customer:
- Email: Uses the user's actual Google email address
- Verification: Inherits Google's email verification status
- External ID: Google's unique user ID (
subclaim) for future authentication - Profile: First and last names from Google profile, with fallbacks
- Security: No password stored - authentication handled entirely by Google
This means Google users work seamlessly with Vendure's order management, promotions, and all customer workflows.
Testing the Integration
To test your Google OAuth integration:
- Start your Vendure server with the plugin configured
- Navigate to your storefront and click "Continue with Google"
- Complete the Google OAuth flow when prompted
- Verify customer creation in the Vendure Dashboard
- Test repeat logins to ensure existing customers are found correctly