Raw
1 import { Table, Prerequisites } from "docs-ui"
2
3 export const metadata = {
4 title: `Google Auth Module Provider`,
5 }
6
7 # {metadata.title}
8
9 In this guide, you’ll learn about the Google Auth Module Provider and how to install and use it in the Auth Module.
10
11 The Google Auth Module Provider allows you to authenticate users with their Google account.
12
13 ## Register the Google Auth Module Provider
14
15 <Prerequisites
16 items={[
17 {
18 text: "Create a project in Google Cloud.",
19 link: "https://cloud.google.com/resource-manager/docs/creating-managing-projects"
20 },
21 {
22 text: "Create Oauth client ID credentials. When setting the Redirect Uri, set it to a URL in your frontend (for example, storefront) that later uses Medusa's callback route to validate the authentication.",
23 link: "https://developers.google.com/identity/protocols/oauth2/web-server#creatingcred"
24 }
25 ]}
26 />
27
28 To use the Google 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 {
40 resolve: "@medusajs/medusa/auth",
41 dependencies: [Modules.CACHE, ContainerRegistrationKeys.LOGGER],
42 options: {
43 mfa: {
44 encryption_key: process.env.AUTH_MFA_ENCRYPTION_KEY,
45 },
46 providers: [
47 // other providers...
48 {
49 resolve: "@medusajs/medusa/auth-emailpass",
50 id: "emailpass",
51 },
52 {
53 resolve: "@medusajs/medusa/auth-google",
54 id: "google",
55 options: {
56 clientId: process.env.GOOGLE_CLIENT_ID,
57 clientSecret: process.env.GOOGLE_CLIENT_SECRET,
58 callbackUrl: process.env.GOOGLE_CALLBACK_URL,
59 },
60 },
61 ],
62 },
63 },
64 ],
65 })
66 ```
67
68 ### Environment Variables
69
70 Make sure to add the necessary environment variables for the above options in `.env`:
71
72 ```plain
73 GOOGLE_CLIENT_ID=<YOUR_GOOGLE_CLIENT_ID>
74 GOOGLE_CLIENT_SECRET=<YOUR_GOOGLE_CLIENT_SECRET>
75 GOOGLE_CALLBACK_URL=<YOUR_GOOGLE_CALLBACK_URL>
76 ```
77
78 ### Module Options
79
80 <Table>
81 <Table.Header>
82 <Table.Row>
83 <Table.HeaderCell>
84 Configuration
85 </Table.HeaderCell>
86 <Table.HeaderCell>
87 Description
88 </Table.HeaderCell>
89 <Table.HeaderCell className="w-1/5">
90 Required
91 </Table.HeaderCell>
92 </Table.Row>
93 </Table.Header>
94 <Table.Body>
95 <Table.Row>
96 <Table.Cell>
97
98 `clientId`
99
100 </Table.Cell>
101 <Table.Cell>
102
103 A string indicating the [Google API Client ID](https://developers.google.com/identity/oauth2/web/guides/get-google-api-clientid).
104
105 </Table.Cell>
106 <Table.Cell>
107
108 Yes
109
110 </Table.Cell>
111 </Table.Row>
112 <Table.Row>
113 <Table.Cell>
114
115 `clientSecret`
116
117 </Table.Cell>
118 <Table.Cell>
119
120 A string indicating the [Google Client Secret](https://support.google.com/cloud/answer/6158849?hl=en#zippy=%2Cstep-create-a-new-client-secret).
121
122 </Table.Cell>
123 <Table.Cell>
124
125 Yes
126
127 </Table.Cell>
128 </Table.Row>
129 <Table.Row>
130 <Table.Cell>
131
132 `callbackUrl`
133
134 </Table.Cell>
135 <Table.Cell>
136
137 A string indicating the URL to redirect to in your frontend after the user completes their authentication in Google.
138
139 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}/google/callback` route.
140
141 </Table.Cell>
142 <Table.Cell>
143
144 Yes
145
146 </Table.Cell>
147 </Table.Row>
148 </Table.Body>
149 </Table>
150
151 ---
152
153 ## Override Callback URL During Authentication
154
155 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.
156
157 The [Authenticate or Login API Route](../../authentication-route/page.mdx#login-route) can accept a `callback_url` body parameter to override the provider's `callbackUrl` option. Learn more in [this documentation](../../authentication-route/page.mdx#login-route).
158
159 ---
160
161 ## Examples
162
163 - [How to implement Google social login in the storefront](../../../../storefront-development/customers/third-party-login/page.mdx)