@medusajs/auth-github 2.22.0-snapshot-20261020204851 → 2.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +56 -0
- package/README.md +105 -9
- package/package.json +7 -3
package/AGENTS.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# @medusajs/auth-github
|
|
2
|
+
|
|
3
|
+
Auth Module provider for "Sign in with GitHub" using the OAuth 2 authorization-code flow.
|
|
4
|
+
|
|
5
|
+
## Using this package
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
module.exports = defineConfig({
|
|
9
|
+
modules: [
|
|
10
|
+
{
|
|
11
|
+
resolve: "@medusajs/medusa/auth",
|
|
12
|
+
options: {
|
|
13
|
+
providers: [
|
|
14
|
+
// overriding `providers` drops the default emailpass provider, so re-add it
|
|
15
|
+
{
|
|
16
|
+
resolve: "@medusajs/medusa/auth-emailpass",
|
|
17
|
+
id: "emailpass",
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
resolve: "@medusajs/medusa/auth-github",
|
|
21
|
+
id: "github",
|
|
22
|
+
options: {
|
|
23
|
+
clientId: process.env.GITHUB_CLIENT_ID,
|
|
24
|
+
clientSecret: process.env.GITHUB_CLIENT_SECRET,
|
|
25
|
+
callbackUrl: process.env.GITHUB_CALLBACK_URL,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
})
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
- Options (`GithubAuthProviderOptions`): `clientId`, `clientSecret`, `callbackUrl`, all required (`validateOptions` throws at boot).
|
|
36
|
+
- Flow: `POST /auth/{actor_type}/github` returns `{ location }` to redirect the browser to; GitHub redirects to your `callbackUrl` (a storefront/admin page), which calls `POST /auth/{actor_type}/github/callback` with the `code` and `state` query params.
|
|
37
|
+
- Docs: https://docs.medusajs.com/resources/commerce-modules/auth/auth-providers/github.md
|
|
38
|
+
- Build a custom auth provider: https://docs.medusajs.com/resources/references/auth/provider.md
|
|
39
|
+
|
|
40
|
+
## Architecture
|
|
41
|
+
|
|
42
|
+
- `src/services/github.ts`: `GithubAuthService extends AbstractAuthModuleProvider`, `static identifier = "github"`.
|
|
43
|
+
- Implements `validateOptions`, `authenticate` (stores a random state key via `authIdentityService.setState` and returns the GitHub authorize URL), `validateCallback` (exchanges the code, fetches `https://api.github.com/user`, upserts the identity). `register` throws `NOT_ALLOWED`.
|
|
44
|
+
- Reference for a custom OAuth redirect provider.
|
|
45
|
+
|
|
46
|
+
## Development
|
|
47
|
+
|
|
48
|
+
- `yarn build`, `yarn test`
|
|
49
|
+
- `yarn test:integration`: `integration-tests/__tests__/services.spec.ts` mocks GitHub with `msw`.
|
|
50
|
+
|
|
51
|
+
## Gotchas
|
|
52
|
+
|
|
53
|
+
- `entity_id` is the GitHub numeric user ID (as a string), not the email. `user_metadata` holds `email`, `name`, `avatar`, `profile_url`, `company`, `two_factor_authentication`, copied from the GitHub `/user` response.
|
|
54
|
+
- Tokens (`access_token`, `refresh_token`, expiry timestamps) are saved in `provider_metadata` and overwritten on every login.
|
|
55
|
+
- A request body `callback_url` overrides the configured `callbackUrl` for that flow; it's stored in state and reused in the token exchange. There is no allowlist (unlike `auth-oidc`).
|
|
56
|
+
- The callback must carry the `state` query param issued by `authenticate`; if it's missing or no longer stored, it returns `"No state provided, or session expired"`.
|
package/README.md
CHANGED
|
@@ -1,11 +1,107 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://www.medusajs.com">
|
|
3
|
+
<picture>
|
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/59018053/229103275-b5e482bb-4601-46e6-8142-244f531cebdb.svg">
|
|
5
|
+
<source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/59018053/229103726-e5b529a3-9b3f-4970-8a1f-c6af37f087bf.svg">
|
|
6
|
+
<img alt="Medusa logo" src="https://user-images.githubusercontent.com/59018053/229103726-e5b529a3-9b3f-4970-8a1f-c6af37f087bf.svg">
|
|
7
|
+
</picture>
|
|
8
|
+
</a>
|
|
9
|
+
</p>
|
|
10
|
+
<h1 align="center">
|
|
11
|
+
@medusajs/auth-github
|
|
12
|
+
</h1>
|
|
2
13
|
|
|
3
|
-
|
|
14
|
+
<h4 align="center">
|
|
15
|
+
<a href="https://docs.medusajs.com">Documentation</a> |
|
|
16
|
+
<a href="https://www.medusajs.com">Website</a>
|
|
17
|
+
</h4>
|
|
4
18
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
19
|
+
<p align="center">
|
|
20
|
+
Building blocks for digital commerce
|
|
21
|
+
</p>
|
|
22
|
+
<p align="center">
|
|
23
|
+
<a href="https://github.com/medusajs/medusa/blob/develop/LICENSE">
|
|
24
|
+
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="Medusa is released under the MIT license." />
|
|
25
|
+
</a>
|
|
26
|
+
<a href="https://github.com/medusajs/medusa/blob/develop/CONTRIBUTING.md">
|
|
27
|
+
<img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat" alt="PRs welcome!" />
|
|
28
|
+
</a>
|
|
29
|
+
<a href="https://discord.gg/xpCwq3Kfn8">
|
|
30
|
+
<img src="https://img.shields.io/badge/chat-on%20discord-7289DA.svg" alt="Discord Chat" />
|
|
31
|
+
</a>
|
|
32
|
+
<a href="https://twitter.com/intent/follow?screen_name=medusajs">
|
|
33
|
+
<img src="https://img.shields.io/twitter/follow/medusajs.svg?label=Follow%20@medusajs" alt="Follow @medusajs" />
|
|
34
|
+
</a>
|
|
35
|
+
</p>
|
|
36
|
+
|
|
37
|
+
GitHub Auth Module Provider for Medusa: lets users and customers log in with their GitHub account through OAuth 2. Use it to add "Log in with GitHub" for customers, admin users, or custom actor types. It ships with `@medusajs/medusa` and is registered through the `@medusajs/medusa/auth-github` path.
|
|
38
|
+
|
|
39
|
+
## At a glance
|
|
40
|
+
|
|
41
|
+
| | |
|
|
42
|
+
| --- | --- |
|
|
43
|
+
| Package | `@medusajs/auth-github` |
|
|
44
|
+
| Type | Module Provider (Auth Module) |
|
|
45
|
+
| Provider ID | `github` |
|
|
46
|
+
| Registered by default | No |
|
|
47
|
+
| Import from | `@medusajs/medusa/auth-github` |
|
|
48
|
+
|
|
49
|
+
## Installation
|
|
50
|
+
|
|
51
|
+
No installation needed. The provider is a dependency of `@medusajs/medusa`.
|
|
52
|
+
|
|
53
|
+
## Usage
|
|
54
|
+
|
|
55
|
+
Register the provider in the Auth Module's `providers` array in `medusa-config.ts`. Passing `providers` replaces the default list, so keep `emailpass` if you still need email/password login:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { defineConfig } from "@medusajs/framework/utils"
|
|
59
|
+
|
|
60
|
+
module.exports = defineConfig({
|
|
61
|
+
// ...
|
|
62
|
+
modules: [
|
|
63
|
+
{
|
|
64
|
+
resolve: "@medusajs/medusa/auth",
|
|
65
|
+
options: {
|
|
66
|
+
providers: [
|
|
67
|
+
{
|
|
68
|
+
resolve: "@medusajs/medusa/auth-emailpass",
|
|
69
|
+
id: "emailpass",
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
resolve: "@medusajs/medusa/auth-github",
|
|
73
|
+
id: "github",
|
|
74
|
+
options: {
|
|
75
|
+
clientId: process.env.GITHUB_CLIENT_ID,
|
|
76
|
+
clientSecret: process.env.GITHUB_CLIENT_SECRET,
|
|
77
|
+
callbackUrl: process.env.GITHUB_CALLBACK_URL,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
})
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The provider's `id` is the one used in authentication routes, such as `/auth/customer/github`.
|
|
88
|
+
|
|
89
|
+
## Configuration
|
|
90
|
+
|
|
91
|
+
| Option | Type | Description | Default |
|
|
92
|
+
| --- | --- | --- | --- |
|
|
93
|
+
| `clientId` | `string` | Required. The OAuth client ID of your GitHub app. | - |
|
|
94
|
+
| `clientSecret` | `string` | Required. The OAuth client secret of your GitHub app. | - |
|
|
95
|
+
| `callbackUrl` | `string` | Required. The URL GitHub redirects to after authentication. Can be overridden per request with a `callback_url` body parameter. | - |
|
|
96
|
+
|
|
97
|
+
| Environment variable | Description |
|
|
98
|
+
| --- | --- |
|
|
99
|
+
| `GITHUB_CLIENT_ID` | Value for `clientId`, as used in the example above. |
|
|
100
|
+
| `GITHUB_CLIENT_SECRET` | Value for `clientSecret`, as used in the example above. |
|
|
101
|
+
| `GITHUB_CALLBACK_URL` | Value for `callbackUrl`, as used in the example above. |
|
|
102
|
+
|
|
103
|
+
## Resources
|
|
104
|
+
|
|
105
|
+
- [GitHub Auth Module Provider](https://docs.medusajs.com/resources/commerce-modules/auth/auth-providers/github)
|
|
106
|
+
- [Auth Providers](https://docs.medusajs.com/resources/commerce-modules/auth/auth-providers)
|
|
107
|
+
- [Auth Module](https://docs.medusajs.com/resources/commerce-modules/auth)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medusajs/auth-github",
|
|
3
|
-
"version": "2.22.0
|
|
3
|
+
"version": "2.22.0",
|
|
4
4
|
"description": "Github OAuth authentication provider for Medusa",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -13,10 +13,14 @@
|
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
15
|
"dist",
|
|
16
|
+
"AGENTS.md",
|
|
16
17
|
"!dist/**/__tests__",
|
|
17
18
|
"!dist/**/__mocks__",
|
|
18
19
|
"!dist/**/__fixtures__"
|
|
19
20
|
],
|
|
21
|
+
"llms": "https://docs.medusajs.com/llms.txt",
|
|
22
|
+
"llmsFull": "https://docs.medusajs.com/llms-full.txt",
|
|
23
|
+
"mcpServer": "https://docs.medusajs.com/mcp",
|
|
20
24
|
"engines": {
|
|
21
25
|
"node": ">=22.22.0"
|
|
22
26
|
},
|
|
@@ -29,10 +33,10 @@
|
|
|
29
33
|
"watch": "yarn run -T tsc --watch"
|
|
30
34
|
},
|
|
31
35
|
"devDependencies": {
|
|
32
|
-
"@medusajs/framework": "2.22.0
|
|
36
|
+
"@medusajs/framework": "2.22.0"
|
|
33
37
|
},
|
|
34
38
|
"peerDependencies": {
|
|
35
|
-
"@medusajs/framework": "2.22.0
|
|
39
|
+
"@medusajs/framework": "2.22.0"
|
|
36
40
|
},
|
|
37
41
|
"keywords": [
|
|
38
42
|
"medusa-provider",
|