GitHub OAuth Authentication
The complete source of the following example plugin can be found here: example-plugins/github-auth-plugin
GitHub OAuth authentication allows customers to sign in using their GitHub accounts, eliminating the need for password-based registration.
This is particularly valuable for developer-focused stores or B2B marketplaces.
This guide shows you how to add GitHub OAuth support to your Vendure store using a custom AuthenticationStrategy.
Creating the Plugin
First, use the Vendure CLI to create a new plugin for GitHub authentication:
This creates a basic plugin structure with the necessary files.
Creating the Authentication Strategy
Now create the GitHub authentication strategy. This handles the OAuth flow and creates customer accounts using GitHub profile data:
The strategy uses Vendure's ExternalAuthenticationService to handle customer creation.
It generates a unique email address for each GitHub user to avoid conflicts, and stores the GitHub username as the external identifier for future logins.
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 GitHub OAuth App
Before you can test the integration, you need to create a GitHub OAuth App:
- Go to GitHub Settings → Developer settings → OAuth Apps
- Click "New OAuth App"
- Fill in the required fields:
- Application name: Your app name (e.g., "My Vendure Store")
- Homepage URL:
http://localhost:3001(your storefront URL) - Authorization callback URL:
http://localhost:3001/auth/github/callback
- Click "Register application"
- Copy the Client ID and generate a Client Secret
The localhost URLs shown here are for local development only. In production, replace localhost:3001 with your actual domain (e.g., https://mystore.com).
Add these credentials to your environment:
Frontend Integration
Creating the Sign-in URL
In your storefront, create a function to generate the GitHub authorization URL:
Handling the Callback
Create a callback handler to process the GitHub response and authenticate with Vendure:
The OAuth flow follows these steps:
- User clicks "Sign in with GitHub" → redirected to GitHub
- User authorizes your app → GitHub redirects back with code and state
- Your callback exchanges the code for user data → creates Vendure session
Using the GraphQL API
Once your plugin is running, the GitHub authentication will be available in your shop API:
Customer Data Management
GitHub-authenticated customers are managed like any other Vendure Customer:
- Email: Generated as
{username}-github@vendure.ioto avoid conflicts - Verification: Automatically verified (GitHub handles email verification)
- External ID: GitHub username stored for future authentication
- Profile: Name extracted from GitHub profile when available
This means GitHub users work seamlessly with Vendure's order management, promotions, and customer workflows.
Testing the Integration
To test your GitHub OAuth integration:
- Start your Vendure server with the plugin configured
- Navigate to your storefront and click the GitHub sign-in link
- Authorize your GitHub app when prompted
- Verify that a new customer is created in the Vendure Dashboard
- Check that subsequent logins find the existing customer account