GitHub Auth Module Provider

In this guide, you’ll learn about the GitHub Auth Module Provider and how to configure it.

The GitHub Auth Module Provider allows you to authenticate users with their GitHub account.

Register the GitHub Auth Module Provider#

To use the GitHub Auth Module Provider, add the module to the array of providers passed to the Auth Module in your medusa-config.ts:

medusa-config.ts
import { Modules, ContainerRegistrationKeys } from "@medusajs/framework/utils"

// ...

module.exports = defineConfig({
  // ...
  modules: [
    {
      resolve: "@medusajs/medusa/auth",
      dependencies: [Modules.CACHE, ContainerRegistrationKeys.LOGGER],
      options: {
        mfa: {
          encryption_key: process.env.AUTH_MFA_ENCRYPTION_KEY,
        },
        providers: [
          // other providers...
          {
            resolve: "@medusajs/medusa/auth-github",
            id: "github",
            options: {
              clientId: process.env.GITHUB_CLIENT_ID,
              clientSecret: process.env.GITHUB_CLIENT_SECRET,
              callbackUrl: process.env.GITHUB_CALLBACK_URL,
            },
          },
        ],
      },
    },
  ],
})

Environment Variables#

Make sure to add the necessary environment variables for the above options in .env:

Code
GITHUB_CLIENT_ID=<YOUR_GITHUB_CLIENT_ID>
GITHUB_CLIENT_SECRET=<YOUR_GITHUB_CLIENT_SECRET>
GITHUB_CALLBACK_URL=<YOUR_GITHUB_CALLBACK_URL>

Module Options#

Configuration

Description

Required

clientId

A string indicating the client ID of your GitHub app.

Yes

clientSecret

A string indicating the client secret of your GitHub app.

Yes

callbackUrl

A string indicating the URL to redirect to in your frontend after the user completes their authentication in GitHub.

At this URL, the frontend will receive a code query parameter. It then sends that code query parameter to the Medusa application's /auth/{actor_type}/github/callback route.

Yes


Allow the GitHub Provider for Customers#

By default, customers and other custom actor types can authenticate with any registered Auth Module Provider, whereas admin users can only authenticate with the emailpass provider. If you deploy your application to Cloud, admin users can also authenticate with their Cloud account.

To specify the actor types that can use the GitHub Auth Module Provider, set the authMethodsPerActor configuration in medusa-config.ts:

medusa-config.ts
module.exports = defineConfig({
  projectConfig: {
    http: {
      authMethodsPerActor: {
        user: ["emailpass"],
        customer: ["emailpass", "github"],
      },
      // ...
    },
    // ...
  },
  // ...
})

This configuration allows customers to authenticate with their email and password or with GitHub, and admin users to authenticate with their email and password only.

Warning: Don't add github to the user actor type. Any GitHub account can authenticate with this provider, and it doesn't have an option to restrict the accounts that can authenticate. So, if you allow the user actor type to use it, anyone with a GitHub account can become an admin user of your store. Learn more in the Auth Module Provider guide.

Override Callback URL During Authentication#

In many cases, you may have different callback URLs for actor types. For example, you may redirect admin users to a different URL than customers after authentication.

The Authenticate or Login API Route accepts a callback_url body parameter to override the provider's callbackUrl option. Learn more in the Auth Flows with Routes guide.


Examples#

Was this page helpful?
Ask Bloom
For assistance in your development, use Claude Code Plugins or Docs MCP server in Cursor, VSCode, etc...FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break
⇧↵