feat(): Add support for jwt asymetric keys (#12813)

* feat(): Add support for jwt asymetric keys

* Create early-chefs-chew.md

* fix unit tests

* Add verify options support

* feedback

* fix unit tests
This commit is contained in:
Adrien de Peretti
2025-06-25 10:29:32 +02:00
committed by GitHub
parent a833c3c98c
commit d517dbd66a
23 changed files with 813 additions and 43 deletions
@@ -117,7 +117,10 @@ describe("defineConfig", function () {
},
"user": {
"options": {
"jwt_options": undefined,
"jwt_public_key": undefined,
"jwt_secret": "supersecret",
"jwt_verify_options": undefined,
},
"resolve": "@medusajs/medusa/user",
},
@@ -132,6 +135,7 @@ describe("defineConfig", function () {
"adminCors": "http://localhost:7000,http://localhost:7001,http://localhost:5173",
"authCors": "http://localhost:7000,http://localhost:7001,http://localhost:5173",
"cookieSecret": "supersecret",
"jwtPublicKey": undefined,
"jwtSecret": "supersecret",
"restrictedFields": {
"store": [
@@ -277,7 +281,10 @@ describe("defineConfig", function () {
},
"user": {
"options": {
"jwt_options": undefined,
"jwt_public_key": undefined,
"jwt_secret": "supersecret",
"jwt_verify_options": undefined,
},
"resolve": "@medusajs/medusa/user",
},
@@ -292,6 +299,7 @@ describe("defineConfig", function () {
"adminCors": "http://localhost:7000,http://localhost:7001,http://localhost:5173",
"authCors": "http://localhost:7000,http://localhost:7001,http://localhost:5173",
"cookieSecret": "supersecret",
"jwtPublicKey": undefined,
"jwtSecret": "supersecret",
"restrictedFields": {
"store": [
@@ -445,7 +453,10 @@ describe("defineConfig", function () {
},
"user": {
"options": {
"jwt_options": undefined,
"jwt_public_key": undefined,
"jwt_secret": "supersecret",
"jwt_verify_options": undefined,
},
"resolve": "@medusajs/medusa/user",
},
@@ -460,6 +471,7 @@ describe("defineConfig", function () {
"adminCors": "http://localhost:7000,http://localhost:7001,http://localhost:5173",
"authCors": "http://localhost:7000,http://localhost:7001,http://localhost:5173",
"cookieSecret": "supersecret",
"jwtPublicKey": undefined,
"jwtSecret": "supersecret",
"restrictedFields": {
"store": [
@@ -614,7 +626,10 @@ describe("defineConfig", function () {
},
"user": {
"options": {
"jwt_options": undefined,
"jwt_public_key": undefined,
"jwt_secret": "supersecret",
"jwt_verify_options": undefined,
},
"resolve": "@medusajs/medusa/user",
},
@@ -629,6 +644,7 @@ describe("defineConfig", function () {
"adminCors": "http://localhost:7000,http://localhost:7001,http://localhost:5173",
"authCors": "http://localhost:7000,http://localhost:7001,http://localhost:5173",
"cookieSecret": "supersecret",
"jwtPublicKey": undefined,
"jwtSecret": "supersecret",
"restrictedFields": {
"store": [
@@ -771,7 +787,10 @@ describe("defineConfig", function () {
},
"user": {
"options": {
"jwt_options": undefined,
"jwt_public_key": undefined,
"jwt_secret": "supersecret",
"jwt_verify_options": undefined,
},
"resolve": "@medusajs/medusa/user",
},
@@ -786,6 +805,7 @@ describe("defineConfig", function () {
"adminCors": "http://localhost:3000",
"authCors": "http://localhost:7000,http://localhost:7001,http://localhost:5173",
"cookieSecret": "supersecret",
"jwtPublicKey": undefined,
"jwtSecret": "supersecret",
"restrictedFields": {
"store": [
@@ -931,7 +951,10 @@ describe("defineConfig", function () {
},
"user": {
"options": {
"jwt_options": undefined,
"jwt_public_key": undefined,
"jwt_secret": "supersecret",
"jwt_verify_options": undefined,
},
"resolve": "@medusajs/medusa/user",
},
@@ -946,6 +969,7 @@ describe("defineConfig", function () {
"adminCors": "http://localhost:3000",
"authCors": "http://localhost:7000,http://localhost:7001,http://localhost:5173",
"cookieSecret": "supersecret",
"jwtPublicKey": undefined,
"jwtSecret": "supersecret",
"restrictedFields": {
"store": [
@@ -1119,7 +1143,10 @@ describe("defineConfig", function () {
},
"user": {
"options": {
"jwt_options": undefined,
"jwt_public_key": undefined,
"jwt_secret": "supersecret",
"jwt_verify_options": undefined,
},
"resolve": "@medusajs/medusa/user",
},
@@ -1139,6 +1166,7 @@ describe("defineConfig", function () {
"adminCors": "http://localhost:7000,http://localhost:7001,http://localhost:5173",
"authCors": "http://localhost:7000,http://localhost:7001,http://localhost:5173",
"cookieSecret": "supersecret",
"jwtPublicKey": undefined,
"jwtSecret": "supersecret",
"restrictedFields": {
"store": [
@@ -1314,7 +1342,10 @@ describe("defineConfig", function () {
},
"user": {
"options": {
"jwt_options": undefined,
"jwt_public_key": undefined,
"jwt_secret": "supersecret",
"jwt_verify_options": undefined,
},
"resolve": "@medusajs/medusa/user",
},
@@ -1334,6 +1365,7 @@ describe("defineConfig", function () {
"adminCors": "http://localhost:7000,http://localhost:7001,http://localhost:5173",
"authCors": "http://localhost:7000,http://localhost:7001,http://localhost:5173",
"cookieSecret": "supersecret",
"jwtPublicKey": undefined,
"jwtSecret": "supersecret",
"restrictedFields": {
"store": [
@@ -1525,7 +1557,10 @@ describe("defineConfig", function () {
},
"user": {
"options": {
"jwt_options": undefined,
"jwt_public_key": undefined,
"jwt_secret": "supersecret",
"jwt_verify_options": undefined,
},
"resolve": "@medusajs/medusa/user",
},
@@ -1545,6 +1580,7 @@ describe("defineConfig", function () {
"adminCors": "http://localhost:7000,http://localhost:7001,http://localhost:5173",
"authCors": "http://localhost:7000,http://localhost:7001,http://localhost:5173",
"cookieSecret": "supersecret",
"jwtPublicKey": undefined,
"jwtSecret": "supersecret",
"restrictedFields": {
"store": [
@@ -1708,7 +1744,10 @@ describe("defineConfig", function () {
},
"user": {
"options": {
"jwt_options": undefined,
"jwt_public_key": undefined,
"jwt_secret": "supersecret",
"jwt_verify_options": undefined,
},
"resolve": "@medusajs/medusa/user",
},
@@ -1723,6 +1762,7 @@ describe("defineConfig", function () {
"adminCors": "http://localhost:3000",
"authCors": "http://localhost:7000,http://localhost:7001,http://localhost:5173",
"cookieSecret": "supersecret",
"jwtPublicKey": undefined,
"jwtSecret": "supersecret",
"restrictedFields": {
"store": [
@@ -48,7 +48,7 @@ export function defineConfig(config: InputConfig = {}): ConfigModule {
const projectConfig = normalizeProjectConfig(config.projectConfig, options)
const adminConfig = normalizeAdminConfig(config.admin)
const modules = resolveModules(config.modules, options)
const modules = resolveModules(config.modules, options, config.projectConfig)
return {
projectConfig,
@@ -132,7 +132,8 @@ export function transformModules(
*/
function resolveModules(
configModules: InputConfig["modules"],
{ isCloud }: { isCloud: boolean }
{ isCloud }: { isCloud: boolean },
projectConfig: InputConfig["projectConfig"]
): Exclude<ConfigModule["modules"], undefined> {
const sharedModules = [
{ resolve: MODULE_PACKAGE_NAMES[Modules.STOCK_LOCATION] },
@@ -166,7 +167,10 @@ function resolveModules(
{
resolve: MODULE_PACKAGE_NAMES[Modules.USER],
options: {
jwt_secret: process.env.JWT_SECRET ?? DEFAULT_SECRET,
jwt_secret: projectConfig?.http?.jwtSecret ?? DEFAULT_SECRET,
jwt_options: projectConfig?.http?.jwtOptions,
jwt_verify_options: projectConfig?.http?.jwtVerifyOptions,
jwt_public_key: projectConfig?.http?.jwtPublicKey,
},
},
{
@@ -318,7 +322,7 @@ function normalizeProjectConfig(
* The defaults to use for the project config. They are shallow merged
* with the user defined config.
*/
return {
const config = {
...(isCloud ? { redisUrl: process.env.REDIS_URL } : {}),
databaseUrl: process.env.DATABASE_URL || DEFAULT_DATABASE_URL,
http: {
@@ -326,6 +330,7 @@ function normalizeProjectConfig(
adminCors: process.env.ADMIN_CORS || DEFAULT_ADMIN_CORS,
authCors: process.env.AUTH_CORS || DEFAULT_ADMIN_CORS,
jwtSecret: process.env.JWT_SECRET || DEFAULT_SECRET,
jwtPublicKey: process.env.JWT_PUBLIC_KEY,
cookieSecret: process.env.COOKIE_SECRET || DEFAULT_SECRET,
restrictedFields: {
store: DEFAULT_STORE_RESTRICTED_FIELDS,
@@ -375,6 +380,8 @@ function normalizeProjectConfig(
},
...restOfProjectConfig,
} satisfies ConfigModule["projectConfig"]
return config
}
function normalizeAdminConfig(