Raw
1 import { Table, Prerequisites } from "docs-ui"
2
3 export const metadata = {
4 title: `GitHub Auth Module Provider`,
5 }
6
7 # {metadata.title}
8
9 In this guide, you’ll learn about the GitHub Auth Module Provider and how to configure it.
10
11 The GitHub Auth Module Provider allows you to authenticate users with their GitHub account.
12
13 ## Register the GitHub Auth Module Provider
14
15 <Prerequisites
16 items={[
17 {
18 text: "Register a GitHub App. When setting the Callback URL, set it to a URL in your frontend that later uses Medusa's callback route to validate the authentication.",
19 link: "https://docs.github.com/en/apps/creating-github-apps/setting-up-a-github-app/creating-a-github-app"
20 },
21 {
22 text: "Retrieve the client ID and client secret of your GitHub App",
23 link: "https://docs.github.com/en/rest/authentication/authenticating-to-the-rest-api?apiVersion=2022-11-28#using-basic-authentication"
24 }
25 ]}
26 />
27
28 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`:
29
30 ```ts title="medusa-config.ts"
31 import { Modules, ContainerRegistrationKeys } from "@medusajs/framework/utils"
32
33 // ...
34
35 module.exports = defineConfig({
36 // ...
37 modules: [
38 {
39 resolve: "@medusajs/medusa/auth",
40 dependencies: [Modules.CACHE, ContainerRegistrationKeys.LOGGER],
41 options: {
42 mfa: {
43 encryption_key: process.env.AUTH_MFA_ENCRYPTION_KEY,
44 },
45 providers: [
46 // other providers...
47 {
48 resolve: "@medusajs/medusa/auth-github",
49 id: "github",
50 options: {
51 clientId: process.env.GITHUB_CLIENT_ID,
52 clientSecret: process.env.GITHUB_CLIENT_SECRET,
53 callbackUrl: process.env.GITHUB_CALLBACK_URL,
54 },
55 },
56 ],
57 },
58 },
59 ],
60 })
61 ```
62
63 ### Environment Variables
64
65 Make sure to add the necessary environment variables for the above options in `.env`:
66
67 ```plain
68 GITHUB_CLIENT_ID=<YOUR_GITHUB_CLIENT_ID>
69 GITHUB_CLIENT_SECRET=<YOUR_GITHUB_CLIENT_SECRET>
70 GITHUB_CALLBACK_URL=<YOUR_GITHUB_CALLBACK_URL>
71 ```
72
73 ### Module Options
74
75 <Table>
76 <Table.Header>
77 <Table.Row>
78 <Table.HeaderCell>
79 Configuration
80 </Table.HeaderCell>
81 <Table.HeaderCell>
82 Description
83 </Table.HeaderCell>
84 <Table.HeaderCell className="w-1/5">
85 Required
86 </Table.HeaderCell>
87 </Table.Row>
88 </Table.Header>
89 <Table.Body>
90 <Table.Row>
91 <Table.Cell>
92
93 `clientId`
94
95 </Table.Cell>
96 <Table.Cell>
97
98 A string indicating the client ID of your GitHub app.
99
100 </Table.Cell>
101 <Table.Cell>
102
103 Yes
104
105 </Table.Cell>
106 </Table.Row>
107 <Table.Row>
108 <Table.Cell>
109
110 `clientSecret`
111
112 </Table.Cell>
113 <Table.Cell>
114
115 A string indicating the client secret of your GitHub app.
116
117 </Table.Cell>
118 <Table.Cell>
119
120 Yes
121
122 </Table.Cell>
123 </Table.Row>
124 <Table.Row>
125 <Table.Cell>
126
127 `callbackUrl`
128
129 </Table.Cell>
130 <Table.Cell>
131
132 A string indicating the URL to redirect to in your frontend after the user completes their authentication in GitHub.
133
134 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.
135
136 </Table.Cell>
137 <Table.Cell>
138
139 Yes
140
141 </Table.Cell>
142 </Table.Row>
143 </Table.Body>
144 </Table>
145
146 ---
147
148 ## Override Callback URL During Authentication
149
150 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.
151
152 The [Authenticate or Login API Route](../../authentication-route/page.mdx#login-route) accepts a `callback_url` body parameter to override the provider's `callbackUrl` option. Learn more in the [Auth Flows with Routes guide](../../authentication-route/page.mdx#login-route).
153
154 ---
155
156 ## Examples
157
158 - [How to implement third-party / social login in the storefront](../../../../storefront-development/customers/third-party-login/page.mdx)