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.
First, use the Vendure CLI to create a new plugin for Google authentication:
This creates a basic plugin structure with the necessary files.
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.
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:
Now update the generated plugin file to register your authentication strategy:
Add the plugin to your Vendure configuration:
Before you can test the integration, you need to create a Google OAuth 2.0 Client:
http://localhost:3001http://localhost:3001/sign-inThe localhost URLs shown here are for local development only. In production, replace localhost:3001 with your actual domain (e.g., https://mystore.com).
Add the client ID to your environment:
For the frontend, we'll use Google's official Identity Services library, which provides a secure and user-friendly sign-in experience:
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:
Once your plugin is running, Google authentication will be available in your shop API:
Google-authenticated customers are managed like any other Vendure Customer:
sub claim) for future authenticationThis means Google users work seamlessly with Vendure's order management, promotions, and all customer workflows.
To test your Google OAuth integration: