Skip to content

Commit 4820cab

Browse files
committed
feat(): Add support for jwt asymetric keys
1 parent b116f75 commit 4820cab

19 files changed

Lines changed: 728 additions & 40 deletions

File tree

integration-tests/helpers/create-admin-user.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from "@medusajs/framework/types"
88
import {
99
ApiKeyType,
10+
ContainerRegistrationKeys,
1011
Modules,
1112
PUBLISHABLE_KEY_HEADER,
1213
} from "@medusajs/framework/utils"
@@ -51,15 +52,19 @@ export const createAdminUser = async (
5152
},
5253
})
5354

55+
const config = container.resolve(ContainerRegistrationKeys.CONFIG_MODULE)
56+
const { projectConfig } = config
57+
const { jwtSecret, jwtOptions } = projectConfig.http
5458
const token = jwt.sign(
5559
{
5660
actor_id: user.id,
5761
actor_type: "user",
5862
auth_identity_id: authIdentity.id,
5963
},
60-
"test",
64+
jwtSecret,
6165
{
6266
expiresIn: "1d",
67+
...jwtOptions,
6368
}
6469
)
6570

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const { defineConfig, Modules } = require("@medusajs/utils")
2+
const { generateKeyPairSync } = require("crypto")
3+
const os = require("os")
4+
5+
const passphrase = "secret"
6+
const { publicKey, privateKey } = generateKeyPairSync("rsa", {
7+
modulusLength: 4096,
8+
publicKeyEncoding: {
9+
type: "spki",
10+
format: "pem",
11+
},
12+
privateKeyEncoding: {
13+
type: "pkcs8",
14+
format: "pem",
15+
cipher: "aes-256-cbc",
16+
passphrase,
17+
},
18+
})
19+
20+
const DB_HOST = process.env.DB_HOST
21+
const DB_USERNAME = process.env.DB_USERNAME
22+
const DB_PASSWORD = process.env.DB_PASSWORD
23+
const DB_NAME = process.env.DB_TEMP_NAME
24+
const DB_URL = `postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}/${DB_NAME}`
25+
process.env.DATABASE_URL = DB_URL
26+
process.env.LOG_LEVEL = "error"
27+
28+
const jwtOptions = {
29+
algorithm: "RS256",
30+
expiresIn: "1h",
31+
issuer: "medusa",
32+
keyid: "medusa",
33+
}
34+
35+
module.exports = defineConfig({
36+
admin: {
37+
disable: true,
38+
},
39+
projectConfig: {
40+
http: {
41+
jwtSecret: {
42+
key: privateKey,
43+
passphrase,
44+
},
45+
jwtPublicKey: publicKey,
46+
jwtOptions: jwtOptions,
47+
},
48+
},
49+
modules: [
50+
{
51+
key: Modules.USER,
52+
options: {
53+
jwt_secret: {
54+
key: privateKey,
55+
passphrase,
56+
},
57+
jwt_public_key: publicKey,
58+
jwt_options: jwtOptions,
59+
},
60+
},
61+
],
62+
})

0 commit comments

Comments
 (0)