Feat(auth): Rename authentication to auth (#6229)
**What** - rename `authenticationModule` -> `authModule`
This commit is contained in:
1 parent
a41aad4bea
commit
512b041929
70 files changed
+245
-147
No files matched your search
File renamed without changes.
@@ -1,4 +1,4 @@
|
|||||||
# @medusajs/authentication
|
# @medusajs/auth
|
||||||
|
|
||||||
## 0.0.2
|
## 0.0.2
|
||||||
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# Auth Module
|
||||||
|
|
||||||
|
The Auth Module is Medusa’s authentication engine engine. It provides functions to authenticate users through identity providers and store metadata about users that can be used for authorization purposes.
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+6
-6
@@ -1,16 +1,16 @@
|
|||||||
import { IAuthenticationModuleService } from "@medusajs/types"
|
import { IAuthModuleService } from "@medusajs/types"
|
||||||
import { MikroOrmWrapper } from "../../../utils"
|
import { MikroOrmWrapper } from "../../../utils"
|
||||||
|
import { Modules } from "@medusajs/modules-sdk"
|
||||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||||
import { createAuthProviders } from "../../../__fixtures__/auth-provider"
|
import { createAuthProviders } from "../../../__fixtures__/auth-provider"
|
||||||
import { createAuthUsers } from "../../../__fixtures__/auth-user"
|
import { createAuthUsers } from "../../../__fixtures__/auth-user"
|
||||||
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
|
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
|
||||||
import { initModules } from "medusa-test-utils/dist"
|
import { initModules } from "medusa-test-utils"
|
||||||
import { Modules } from "@medusajs/modules-sdk"
|
|
||||||
|
|
||||||
jest.setTimeout(30000)
|
jest.setTimeout(30000)
|
||||||
|
|
||||||
describe("AuthenticationModuleService - AuthProvider", () => {
|
describe("AuthModuleService - AuthProvider", () => {
|
||||||
let service: IAuthenticationModuleService
|
let service: IAuthModuleService
|
||||||
let testManager: SqlEntityManager
|
let testManager: SqlEntityManager
|
||||||
let shutdownFunc: () => Promise<void>
|
let shutdownFunc: () => Promise<void>
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ describe("AuthenticationModuleService - AuthProvider", () => {
|
|||||||
|
|
||||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||||
|
|
||||||
service = medusaApp.modules[Modules.AUTHENTICATION]
|
service = medusaApp.modules[Modules.AUTH]
|
||||||
|
|
||||||
shutdownFunc = shutdown
|
shutdownFunc = shutdown
|
||||||
})
|
})
|
||||||
+7
-8
@@ -1,17 +1,16 @@
|
|||||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
import { IAuthModuleService } from "@medusajs/types"
|
||||||
|
|
||||||
import { MikroOrmWrapper } from "../../../utils"
|
import { MikroOrmWrapper } from "../../../utils"
|
||||||
|
import { Modules } from "@medusajs/modules-sdk"
|
||||||
|
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||||
import { createAuthProviders } from "../../../__fixtures__/auth-provider"
|
import { createAuthProviders } from "../../../__fixtures__/auth-provider"
|
||||||
import { createAuthUsers } from "../../../__fixtures__/auth-user"
|
import { createAuthUsers } from "../../../__fixtures__/auth-user"
|
||||||
import { IAuthenticationModuleService } from "@medusajs/types"
|
|
||||||
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
|
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
|
||||||
import { initModules } from "medusa-test-utils/dist"
|
import { initModules } from "medusa-test-utils"
|
||||||
import { Modules } from "@medusajs/modules-sdk"
|
|
||||||
|
|
||||||
jest.setTimeout(30000)
|
jest.setTimeout(30000)
|
||||||
|
|
||||||
describe("AuthenticationModuleService - AuthUser", () => {
|
describe("AuthModuleService - AuthUser", () => {
|
||||||
let service: IAuthenticationModuleService
|
let service: IAuthModuleService
|
||||||
let testManager: SqlEntityManager
|
let testManager: SqlEntityManager
|
||||||
let shutdownFunc: () => Promise<void>
|
let shutdownFunc: () => Promise<void>
|
||||||
|
|
||||||
@@ -20,7 +19,7 @@ describe("AuthenticationModuleService - AuthUser", () => {
|
|||||||
|
|
||||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||||
|
|
||||||
service = medusaApp.modules[Modules.AUTHENTICATION]
|
service = medusaApp.modules[Modules.AUTH]
|
||||||
|
|
||||||
shutdownFunc = shutdown
|
shutdownFunc = shutdown
|
||||||
})
|
})
|
||||||
+11
-11
@@ -1,16 +1,16 @@
|
|||||||
import { MedusaModule, Modules } from "@medusajs/modules-sdk"
|
import { MedusaModule, Modules } from "@medusajs/modules-sdk"
|
||||||
|
|
||||||
import { IAuthenticationModuleService } from "@medusajs/types"
|
import { IAuthModuleService } from "@medusajs/types"
|
||||||
import { MikroOrmWrapper } from "../../../utils"
|
import { MikroOrmWrapper } from "../../../utils"
|
||||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||||
import { createAuthProviders } from "../../../__fixtures__/auth-provider"
|
import { createAuthProviders } from "../../../__fixtures__/auth-provider"
|
||||||
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
|
import { getInitModuleConfig } from "../../../utils/get-init-module-config"
|
||||||
import { initModules } from "medusa-test-utils/dist"
|
import { initModules } from "medusa-test-utils"
|
||||||
|
|
||||||
jest.setTimeout(30000)
|
jest.setTimeout(30000)
|
||||||
|
|
||||||
describe("AuthenticationModuleService - AuthProvider", () => {
|
describe("AuthModuleService - AuthProvider", () => {
|
||||||
let service: IAuthenticationModuleService
|
let service: IAuthModuleService
|
||||||
let testManager: SqlEntityManager
|
let testManager: SqlEntityManager
|
||||||
let shutdownFunc: () => Promise<void>
|
let shutdownFunc: () => Promise<void>
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ describe("AuthenticationModuleService - AuthProvider", () => {
|
|||||||
|
|
||||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||||
|
|
||||||
service = medusaApp.modules[Modules.AUTHENTICATION]
|
service = medusaApp.modules[Modules.AUTH]
|
||||||
|
|
||||||
shutdownFunc = shutdown
|
shutdownFunc = shutdown
|
||||||
})
|
})
|
||||||
@@ -50,8 +50,8 @@ describe("AuthenticationModuleService - AuthProvider", () => {
|
|||||||
expect(serialized).toEqual(
|
expect(serialized).toEqual(
|
||||||
expect.arrayContaining([
|
expect.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
provider: "usernamePassword",
|
provider: "emailpass",
|
||||||
name: "Username/Password Authentication",
|
name: "Email/Password Authentication",
|
||||||
}),
|
}),
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
provider: "google",
|
provider: "google",
|
||||||
@@ -71,7 +71,7 @@ describe("AuthenticationModuleService - AuthProvider", () => {
|
|||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
const { success, error } = await service.authenticate("notRegistered", {})
|
const { success, error } = await service.authenticate("notRegistered", {} as any)
|
||||||
|
|
||||||
expect(success).toBe(false)
|
expect(success).toBe(false)
|
||||||
expect(error).toEqual(
|
expect(error).toEqual(
|
||||||
@@ -81,15 +81,15 @@ describe("AuthenticationModuleService - AuthProvider", () => {
|
|||||||
|
|
||||||
it("fails to authenticate using a valid provider with an invalid scope", async () => {
|
it("fails to authenticate using a valid provider with an invalid scope", async () => {
|
||||||
const { success, error } = await service.authenticate(
|
const { success, error } = await service.authenticate(
|
||||||
"usernamePassword",
|
"emailpass",
|
||||||
{
|
{
|
||||||
scope: "non-existing",
|
scope: "non-existing",
|
||||||
}
|
} as any
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(success).toBe(false)
|
expect(success).toBe(false)
|
||||||
expect(error).toEqual(
|
expect(error).toEqual(
|
||||||
`Scope "non-existing" is not valid for provider usernamePassword`
|
`Scope "non-existing" is not valid for provider emailpass`
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
+10
-10
@@ -1,6 +1,6 @@
|
|||||||
|
import { AuthenticationInput, IAuthModuleService } from "@medusajs/types"
|
||||||
import { MedusaModule, Modules } from "@medusajs/modules-sdk"
|
import { MedusaModule, Modules } from "@medusajs/modules-sdk"
|
||||||
|
|
||||||
import { IAuthenticationModuleService } from "@medusajs/types"
|
|
||||||
import { MikroOrmWrapper } from "../../../utils"
|
import { MikroOrmWrapper } from "../../../utils"
|
||||||
import Scrypt from "scrypt-kdf"
|
import Scrypt from "scrypt-kdf"
|
||||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||||
@@ -15,8 +15,8 @@ const seedDefaultData = async (testManager) => {
|
|||||||
await createAuthUsers(testManager)
|
await createAuthUsers(testManager)
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("AuthenticationModuleService - AuthProvider", () => {
|
describe("AuthModuleService - AuthProvider", () => {
|
||||||
let service: IAuthenticationModuleService
|
let service: IAuthModuleService
|
||||||
let testManager: SqlEntityManager
|
let testManager: SqlEntityManager
|
||||||
let shutdownFunc: () => Promise<void>
|
let shutdownFunc: () => Promise<void>
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ describe("AuthenticationModuleService - AuthProvider", () => {
|
|||||||
|
|
||||||
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
const { medusaApp, shutdown } = await initModules(initModulesConfig)
|
||||||
|
|
||||||
service = medusaApp.modules[Modules.AUTHENTICATION]
|
service = medusaApp.modules[Modules.AUTH]
|
||||||
|
|
||||||
shutdownFunc = shutdown
|
shutdownFunc = shutdown
|
||||||
})
|
})
|
||||||
@@ -60,7 +60,7 @@ describe("AuthenticationModuleService - AuthProvider", () => {
|
|||||||
await createAuthUsers(testManager, [
|
await createAuthUsers(testManager, [
|
||||||
// Add authenticated user
|
// Add authenticated user
|
||||||
{
|
{
|
||||||
provider: "usernamePassword",
|
provider: "emailpass",
|
||||||
entity_id: email,
|
entity_id: email,
|
||||||
provider_metadata: {
|
provider_metadata: {
|
||||||
password: passwordHash,
|
password: passwordHash,
|
||||||
@@ -68,7 +68,7 @@ describe("AuthenticationModuleService - AuthProvider", () => {
|
|||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
const res = await service.authenticate("usernamePassword", {
|
const res = await service.authenticate("emailpass", {
|
||||||
body: {
|
body: {
|
||||||
email: "test@test.com",
|
email: "test@test.com",
|
||||||
password: password,
|
password: password,
|
||||||
@@ -90,7 +90,7 @@ describe("AuthenticationModuleService - AuthProvider", () => {
|
|||||||
|
|
||||||
await seedDefaultData(testManager)
|
await seedDefaultData(testManager)
|
||||||
|
|
||||||
const res = await service.authenticate("usernamePassword", {
|
const res = await service.authenticate("emailpass", {
|
||||||
body: { email: "test@test.com" },
|
body: { email: "test@test.com" },
|
||||||
scope: "store",
|
scope: "store",
|
||||||
})
|
})
|
||||||
@@ -104,7 +104,7 @@ describe("AuthenticationModuleService - AuthProvider", () => {
|
|||||||
it("fails when no email is given", async () => {
|
it("fails when no email is given", async () => {
|
||||||
await seedDefaultData(testManager)
|
await seedDefaultData(testManager)
|
||||||
|
|
||||||
const res = await service.authenticate("usernamePassword", {
|
const res = await service.authenticate("emailpass", {
|
||||||
body: { password: "supersecret" },
|
body: { password: "supersecret" },
|
||||||
scope: "store",
|
scope: "store",
|
||||||
})
|
})
|
||||||
@@ -126,7 +126,7 @@ describe("AuthenticationModuleService - AuthProvider", () => {
|
|||||||
await createAuthUsers(testManager, [
|
await createAuthUsers(testManager, [
|
||||||
// Add authenticated user
|
// Add authenticated user
|
||||||
{
|
{
|
||||||
provider: "usernamePassword",
|
provider: "emailpass",
|
||||||
entity_id: email,
|
entity_id: email,
|
||||||
provider_metadata: {
|
provider_metadata: {
|
||||||
password_hash: passwordHash,
|
password_hash: passwordHash,
|
||||||
@@ -134,7 +134,7 @@ describe("AuthenticationModuleService - AuthProvider", () => {
|
|||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
const res = await service.authenticate("usernamePassword", {
|
const res = await service.authenticate("emailpass", {
|
||||||
body: {
|
body: {
|
||||||
email: "test@test.com",
|
email: "test@test.com",
|
||||||
password: "password",
|
password: "password",
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
if (typeof process.env.DB_TEMP_NAME === "undefined") {
|
||||||
|
const tempName = parseInt(process.env.JEST_WORKER_ID || "1")
|
||||||
|
process.env.DB_TEMP_NAME = `medusa-auth-integration-${tempName}`
|
||||||
|
}
|
||||||
|
|
||||||
|
process.env.MEDUSA_AUTH_DB_SCHEMA = "public"
|
||||||
File renamed without changes.
+1
-1
@@ -2,5 +2,5 @@ import { ModuleServiceInitializeOptions } from "@medusajs/types"
|
|||||||
|
|
||||||
export const databaseOptions: ModuleServiceInitializeOptions["database"] = {
|
export const databaseOptions: ModuleServiceInitializeOptions["database"] = {
|
||||||
schema: "public",
|
schema: "public",
|
||||||
clientUrl: "medusa-authentication-test",
|
clientUrl: "medusa-auth-test",
|
||||||
}
|
}
|
||||||
+3
-3
@@ -1,9 +1,9 @@
|
|||||||
|
import * as AuthModels from "@models"
|
||||||
|
|
||||||
import { TestDatabaseUtils } from "medusa-test-utils"
|
import { TestDatabaseUtils } from "medusa-test-utils"
|
||||||
|
|
||||||
import * as AuthenticationModels from "@models"
|
|
||||||
|
|
||||||
const pathToMigrations = "../../src/migrations"
|
const pathToMigrations = "../../src/migrations"
|
||||||
const mikroOrmEntities = AuthenticationModels as unknown as any[]
|
const mikroOrmEntities = AuthModels as unknown as any[]
|
||||||
|
|
||||||
export const MikroOrmWrapper = TestDatabaseUtils.getMikroOrmWrapper(
|
export const MikroOrmWrapper = TestDatabaseUtils.getMikroOrmWrapper(
|
||||||
mikroOrmEntities,
|
mikroOrmEntities,
|
||||||
+5
-5
@@ -7,12 +7,12 @@ export function getInitModuleConfig() {
|
|||||||
defaultAdapterOptions: {
|
defaultAdapterOptions: {
|
||||||
database: {
|
database: {
|
||||||
clientUrl: DB_URL,
|
clientUrl: DB_URL,
|
||||||
schema: process.env.MEDUSA_AUTHENTICATION_DB_SCHEMA,
|
schema: process.env.MEDUSA_AUTH_DB_SCHEMA,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
providers: [
|
providers: [
|
||||||
{
|
{
|
||||||
name: "usernamePassword",
|
name: "emailpass",
|
||||||
scopes: {
|
scopes: {
|
||||||
admin: {},
|
admin: {},
|
||||||
store: {},
|
store: {},
|
||||||
@@ -24,8 +24,8 @@ export function getInitModuleConfig() {
|
|||||||
const injectedDependencies = {}
|
const injectedDependencies = {}
|
||||||
|
|
||||||
const modulesConfig_ = {
|
const modulesConfig_ = {
|
||||||
[Modules.AUTHENTICATION]: {
|
[Modules.AUTH]: {
|
||||||
definition: ModulesDefinition[Modules.AUTHENTICATION],
|
definition: ModulesDefinition[Modules.AUTH],
|
||||||
options: moduleOptions,
|
options: moduleOptions,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ export function getInitModuleConfig() {
|
|||||||
modulesConfig: modulesConfig_,
|
modulesConfig: modulesConfig_,
|
||||||
databaseConfig: {
|
databaseConfig: {
|
||||||
clientUrl: DB_URL,
|
clientUrl: DB_URL,
|
||||||
schema: process.env.MEDUSA_AUTHENTICATION_DB_SCHEMA,
|
schema: process.env.MEDUSA_AUTH_DB_SCHEMA,
|
||||||
},
|
},
|
||||||
joinerConfig: [],
|
joinerConfig: [],
|
||||||
}
|
}
|
||||||
File renamed without changes.
File renamed without changes.
+1
-1
@@ -3,6 +3,6 @@ import * as entities from "./src/models"
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
entities: Object.values(entities),
|
entities: Object.values(entities),
|
||||||
schema: "public",
|
schema: "public",
|
||||||
clientUrl: "postgres://postgres@localhost/medusa-authentication",
|
clientUrl: "postgres://postgres@localhost/medusa-auth",
|
||||||
type: "postgresql",
|
type: "postgresql",
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@medusajs/authentication",
|
"name": "@medusajs/auth",
|
||||||
"version": "0.0.2",
|
"version": "0.0.2",
|
||||||
"description": "Medusa Authentication module",
|
"description": "Medusa Auth module",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
"files": [
|
"files": [
|
||||||
@@ -11,12 +11,12 @@
|
|||||||
"node": ">=16"
|
"node": ">=16"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"medusa-authentication-seed": "dist/scripts/bin/run-seed.js"
|
"medusa-auth-seed": "dist/scripts/bin/run-seed.js"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/medusajs/medusa",
|
"url": "https://github.com/medusajs/medusa",
|
||||||
"directory": "packages/authentication"
|
"directory": "packages/auth"
|
||||||
},
|
},
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
File renamed without changes.
+6
-6
@@ -5,7 +5,7 @@ import {
|
|||||||
MedusaModule,
|
MedusaModule,
|
||||||
Modules,
|
Modules,
|
||||||
} from "@medusajs/modules-sdk"
|
} from "@medusajs/modules-sdk"
|
||||||
import { IAuthenticationModuleService, ModulesSdkTypes } from "@medusajs/types"
|
import { IAuthModuleService, ModulesSdkTypes } from "@medusajs/types"
|
||||||
|
|
||||||
import { InitializeModuleInjectableDependencies } from "../types"
|
import { InitializeModuleInjectableDependencies } from "../types"
|
||||||
import { moduleDefinition } from "../module-definition"
|
import { moduleDefinition } from "../module-definition"
|
||||||
@@ -16,10 +16,10 @@ export const initialize = async (
|
|||||||
| ModulesSdkTypes.ModuleServiceInitializeOptions
|
| ModulesSdkTypes.ModuleServiceInitializeOptions
|
||||||
| ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions,
|
| ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions,
|
||||||
injectedDependencies?: InitializeModuleInjectableDependencies
|
injectedDependencies?: InitializeModuleInjectableDependencies
|
||||||
): Promise<IAuthenticationModuleService> => {
|
): Promise<IAuthModuleService> => {
|
||||||
const loaded = await MedusaModule.bootstrap<IAuthenticationModuleService>({
|
const loaded = await MedusaModule.bootstrap<IAuthModuleService>({
|
||||||
moduleKey: Modules.AUTHENTICATION,
|
moduleKey: Modules.AUTH,
|
||||||
defaultPath: MODULE_PACKAGE_NAMES[Modules.AUTHENTICATION],
|
defaultPath: MODULE_PACKAGE_NAMES[Modules.AUTH],
|
||||||
declaration: options as
|
declaration: options as
|
||||||
| InternalModuleDeclaration
|
| InternalModuleDeclaration
|
||||||
| ExternalModuleDeclaration, // TODO: Add provider configuration
|
| ExternalModuleDeclaration, // TODO: Add provider configuration
|
||||||
@@ -27,5 +27,5 @@ export const initialize = async (
|
|||||||
moduleExports: moduleDefinition,
|
moduleExports: moduleDefinition,
|
||||||
})
|
})
|
||||||
|
|
||||||
return loaded[Modules.AUTHENTICATION]
|
return loaded[Modules.AUTH]
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Modules } from "@medusajs/modules-sdk"
|
|
||||||
import { ModuleJoinerConfig } from "@medusajs/types"
|
|
||||||
import { MapToConfig } from "@medusajs/utils"
|
|
||||||
import { AuthUser } from "@models"
|
import { AuthUser } from "@models"
|
||||||
|
import { MapToConfig } from "@medusajs/utils"
|
||||||
|
import { ModuleJoinerConfig } from "@medusajs/types"
|
||||||
|
import { Modules } from "@medusajs/modules-sdk"
|
||||||
|
|
||||||
export const LinkableKeys = {
|
export const LinkableKeys = {
|
||||||
auth_user_id: AuthUser.name,
|
auth_user_id: AuthUser.name,
|
||||||
@@ -19,7 +19,7 @@ Object.entries(LinkableKeys).forEach(([key, value]) => {
|
|||||||
export const entityNameToLinkableKeysMap: MapToConfig = entityLinkableKeysMap
|
export const entityNameToLinkableKeysMap: MapToConfig = entityLinkableKeysMap
|
||||||
|
|
||||||
export const joinerConfig: ModuleJoinerConfig = {
|
export const joinerConfig: ModuleJoinerConfig = {
|
||||||
serviceName: Modules.AUTHENTICATION,
|
serviceName: Modules.AUTH,
|
||||||
primaryKeys: ["id"],
|
primaryKeys: ["id"],
|
||||||
linkableKeys: LinkableKeys,
|
linkableKeys: LinkableKeys,
|
||||||
alias: {
|
alias: {
|
||||||
+6
-4
@@ -1,12 +1,14 @@
|
|||||||
|
import * as AuthModels from "../models"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
InternalModuleDeclaration,
|
InternalModuleDeclaration,
|
||||||
LoaderOptions,
|
LoaderOptions,
|
||||||
Modules,
|
Modules,
|
||||||
} from "@medusajs/modules-sdk"
|
} from "@medusajs/modules-sdk"
|
||||||
|
|
||||||
|
import { EntitySchema } from "@mikro-orm/core"
|
||||||
import { ModulesSdkTypes } from "@medusajs/types"
|
import { ModulesSdkTypes } from "@medusajs/types"
|
||||||
import { ModulesSdkUtils } from "@medusajs/utils"
|
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||||
import { EntitySchema } from "@mikro-orm/core"
|
|
||||||
import * as AuthenticationModules from "../models"
|
|
||||||
|
|
||||||
export default async (
|
export default async (
|
||||||
{
|
{
|
||||||
@@ -20,12 +22,12 @@ export default async (
|
|||||||
moduleDeclaration?: InternalModuleDeclaration
|
moduleDeclaration?: InternalModuleDeclaration
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
const entities = Object.values(
|
const entities = Object.values(
|
||||||
AuthenticationModules
|
AuthModels
|
||||||
) as unknown as EntitySchema[]
|
) as unknown as EntitySchema[]
|
||||||
const pathToMigrations = __dirname + "/../migrations"
|
const pathToMigrations = __dirname + "/../migrations"
|
||||||
|
|
||||||
await ModulesSdkUtils.mikroOrmConnectionLoader({
|
await ModulesSdkUtils.mikroOrmConnectionLoader({
|
||||||
moduleName: Modules.AUTHENTICATION,
|
moduleName: Modules.AUTH,
|
||||||
entities,
|
entities,
|
||||||
container,
|
container,
|
||||||
options,
|
options,
|
||||||
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,71 @@
|
|||||||
|
import * as defaultProviders from "@providers"
|
||||||
|
|
||||||
|
import {
|
||||||
|
asClass,
|
||||||
|
AwilixContainer,
|
||||||
|
ClassOrFunctionReturning,
|
||||||
|
Constructor,
|
||||||
|
Resolver,
|
||||||
|
} from "awilix"
|
||||||
|
import {
|
||||||
|
AuthModuleProviderConfig,
|
||||||
|
AuthProviderScope,
|
||||||
|
LoaderOptions,
|
||||||
|
ModulesSdkTypes,
|
||||||
|
} from "@medusajs/types"
|
||||||
|
|
||||||
|
type AuthModuleProviders = {
|
||||||
|
providers: AuthModuleProviderConfig[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async ({
|
||||||
|
container,
|
||||||
|
options,
|
||||||
|
}: LoaderOptions<
|
||||||
|
(
|
||||||
|
| ModulesSdkTypes.ModuleServiceInitializeOptions
|
||||||
|
| ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions
|
||||||
|
) &
|
||||||
|
AuthModuleProviders
|
||||||
|
>): Promise<void> => {
|
||||||
|
const providerMap = new Map(
|
||||||
|
options?.providers?.map((provider) => [provider.name, provider.scopes]) ??
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
// if(options?.providers?.length) {
|
||||||
|
// TODO: implement plugin provider registration
|
||||||
|
// }
|
||||||
|
|
||||||
|
const providersToLoad = Object.values(defaultProviders)
|
||||||
|
|
||||||
|
for (const provider of providersToLoad) {
|
||||||
|
container.register({
|
||||||
|
[`auth_provider_${provider.PROVIDER}`]: asClass(
|
||||||
|
provider as Constructor<any>
|
||||||
|
)
|
||||||
|
.singleton()
|
||||||
|
.inject(() => ({ scopes: providerMap.get(provider.PROVIDER) ?? {} })),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
container.register({
|
||||||
|
[`auth_providers`]: asArray(providersToLoad, providerMap),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function asArray(
|
||||||
|
resolvers: (ClassOrFunctionReturning<unknown> | Resolver<unknown>)[],
|
||||||
|
providerScopeMap: Map<string, Record<string, AuthProviderScope>>
|
||||||
|
): { resolve: (container: AwilixContainer) => unknown[] } {
|
||||||
|
return {
|
||||||
|
resolve: (container: AwilixContainer) =>
|
||||||
|
resolvers.map((resolver) =>
|
||||||
|
asClass(resolver as Constructor<any>)
|
||||||
|
.inject(() => ({
|
||||||
|
// @ts-ignore
|
||||||
|
scopes: providerScopeMap.get(resolver.PROVIDER) ?? {},
|
||||||
|
}))
|
||||||
|
.resolve(container)
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+7
-6
@@ -1,14 +1,15 @@
|
|||||||
import { Modules } from "@medusajs/modules-sdk"
|
|
||||||
import { ModuleExports } from "@medusajs/types"
|
|
||||||
import { ModulesSdkUtils } from "@medusajs/utils"
|
|
||||||
import * as Models from "@models"
|
import * as Models from "@models"
|
||||||
import { AuthenticationModuleService } from "@services"
|
|
||||||
|
import { AuthModuleService } from "@services"
|
||||||
|
import { ModuleExports } from "@medusajs/types"
|
||||||
|
import { Modules } from "@medusajs/modules-sdk"
|
||||||
|
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||||
import loadConnection from "./loaders/connection"
|
import loadConnection from "./loaders/connection"
|
||||||
import loadContainer from "./loaders/container"
|
import loadContainer from "./loaders/container"
|
||||||
import loadProviders from "./loaders/providers"
|
import loadProviders from "./loaders/providers"
|
||||||
|
|
||||||
const migrationScriptOptions = {
|
const migrationScriptOptions = {
|
||||||
moduleName: Modules.AUTHENTICATION,
|
moduleName: Modules.AUTH,
|
||||||
models: Models,
|
models: Models,
|
||||||
pathToMigrations: __dirname + "/migrations",
|
pathToMigrations: __dirname + "/migrations",
|
||||||
}
|
}
|
||||||
@@ -20,7 +21,7 @@ export const revertMigration = ModulesSdkUtils.buildRevertMigrationScript(
|
|||||||
migrationScriptOptions
|
migrationScriptOptions
|
||||||
)
|
)
|
||||||
|
|
||||||
const service = AuthenticationModuleService
|
const service = AuthModuleService
|
||||||
const loaders = [loadContainer, loadConnection, loadProviders] as any
|
const loaders = [loadContainer, loadConnection, loadProviders] as any
|
||||||
|
|
||||||
export const moduleDefinition: ModuleExports = {
|
export const moduleDefinition: ModuleExports = {
|
||||||
+7
-7
@@ -1,12 +1,12 @@
|
|||||||
import { AbstractAuthenticationModuleProvider, isString } from "@medusajs/utils"
|
import { AbstractAuthModuleProvider, isString } from "@medusajs/utils"
|
||||||
|
import { AuthenticationInput, AuthenticationResponse } from "@medusajs/types"
|
||||||
|
|
||||||
import { AuthUserService } from "@services"
|
import { AuthUserService } from "@services"
|
||||||
import { AuthenticationInput, AuthenticationResponse } from "@medusajs/types"
|
|
||||||
import Scrypt from "scrypt-kdf"
|
import Scrypt from "scrypt-kdf"
|
||||||
|
|
||||||
class UsernamePasswordProvider extends AbstractAuthenticationModuleProvider {
|
class EmailPasswordProvider extends AbstractAuthModuleProvider {
|
||||||
public static PROVIDER = "usernamePassword"
|
public static PROVIDER = "emailpass"
|
||||||
public static DISPLAY_NAME = "Username/Password Authentication"
|
public static DISPLAY_NAME = "Email/Password Authentication"
|
||||||
|
|
||||||
protected readonly authUserSerivce_: AuthUserService
|
protected readonly authUserSerivce_: AuthUserService
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ class UsernamePasswordProvider extends AbstractAuthenticationModuleProvider {
|
|||||||
|
|
||||||
const authUser = await this.authUserSerivce_.retrieveByProviderAndEntityId(
|
const authUser = await this.authUserSerivce_.retrieveByProviderAndEntityId(
|
||||||
email,
|
email,
|
||||||
UsernamePasswordProvider.PROVIDER
|
EmailPasswordProvider.PROVIDER
|
||||||
)
|
)
|
||||||
|
|
||||||
const password_hash = authUser.provider_metadata?.password
|
const password_hash = authUser.provider_metadata?.password
|
||||||
@@ -61,4 +61,4 @@ class UsernamePasswordProvider extends AbstractAuthenticationModuleProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default UsernamePasswordProvider
|
export default EmailPasswordProvider
|
||||||
+5
-5
@@ -1,14 +1,14 @@
|
|||||||
import {
|
import {
|
||||||
AbstractAuthenticationModuleProvider,
|
AbstractAuthModuleProvider,
|
||||||
MedusaError,
|
MedusaError,
|
||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
import { AuthProviderService, AuthUserService } from "@services"
|
|
||||||
import jwt, { JwtPayload } from "jsonwebtoken"
|
|
||||||
import {
|
import {
|
||||||
|
AuthProviderScope,
|
||||||
AuthenticationInput,
|
AuthenticationInput,
|
||||||
AuthenticationResponse,
|
AuthenticationResponse,
|
||||||
AuthProviderScope,
|
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
|
import { AuthProviderService, AuthUserService } from "@services"
|
||||||
|
import jwt, { JwtPayload } from "jsonwebtoken"
|
||||||
import { AuthorizationCode } from "simple-oauth2"
|
import { AuthorizationCode } from "simple-oauth2"
|
||||||
import url from "url"
|
import url from "url"
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ type ProviderConfig = {
|
|||||||
callbackURL: string
|
callbackURL: string
|
||||||
}
|
}
|
||||||
|
|
||||||
class GoogleProvider extends AbstractAuthenticationModuleProvider {
|
class GoogleProvider extends AbstractAuthModuleProvider {
|
||||||
public static PROVIDER = "google"
|
public static PROVIDER = "google"
|
||||||
public static DISPLAY_NAME = "Google Authentication"
|
public static DISPLAY_NAME = "Google Authentication"
|
||||||
|
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export { default as EmailPasswordProvider } from "./email-password"
|
||||||
|
export { default as GoogleProvider } from "./google"
|
||||||
File renamed without changes.
+1
-1
@@ -11,7 +11,7 @@ export default (async () => {
|
|||||||
config()
|
config()
|
||||||
if (!path) {
|
if (!path) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`filePath is required.${EOL}Example: medusa-authentication-seed <filePath>`
|
`filePath is required.${EOL}Example: medusa-auth-seed <filePath>`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
import { Modules } from "@medusajs/modules-sdk"
|
import * as AuthModels from "@models"
|
||||||
import { LoaderOptions, Logger, ModulesSdkTypes } from "@medusajs/types"
|
|
||||||
import { DALUtils, ModulesSdkUtils } from "@medusajs/utils"
|
import { DALUtils, ModulesSdkUtils } from "@medusajs/utils"
|
||||||
import { EntitySchema } from "@mikro-orm/core"
|
import { LoaderOptions, Logger, ModulesSdkTypes } from "@medusajs/types"
|
||||||
import * as AuthenticationModels from "@models"
|
|
||||||
import { EOL } from "os"
|
import { EOL } from "os"
|
||||||
|
import { EntitySchema } from "@mikro-orm/core"
|
||||||
|
import { Modules } from "@medusajs/modules-sdk"
|
||||||
import { resolve } from "path"
|
import { resolve } from "path"
|
||||||
|
|
||||||
export async function run({
|
export async function run({
|
||||||
@@ -32,11 +34,11 @@ export async function run({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const dbData = ModulesSdkUtils.loadDatabaseConfig(
|
const dbData = ModulesSdkUtils.loadDatabaseConfig(
|
||||||
Modules.AUTHENTICATION,
|
Modules.AUTH,
|
||||||
options
|
options
|
||||||
)!
|
)!
|
||||||
const entities = Object.values(
|
const entities = Object.values(
|
||||||
AuthenticationModels
|
AuthModels
|
||||||
) as unknown as EntitySchema[]
|
) as unknown as EntitySchema[]
|
||||||
const pathToMigrations = __dirname + "/../migrations"
|
const pathToMigrations = __dirname + "/../migrations"
|
||||||
|
|
||||||
File renamed without changes.
+27
-27
@@ -1,7 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
AuthenticationInput,
|
AuthenticationInput,
|
||||||
AuthenticationResponse,
|
AuthenticationResponse,
|
||||||
AuthenticationTypes,
|
AuthTypes,
|
||||||
Context,
|
Context,
|
||||||
DAL,
|
DAL,
|
||||||
FindConfig,
|
FindConfig,
|
||||||
@@ -16,7 +16,7 @@ import { joinerConfig } from "../joiner-config"
|
|||||||
import { AuthProviderService, AuthUserService } from "@services"
|
import { AuthProviderService, AuthUserService } from "@services"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
AbstractAuthenticationModuleProvider,
|
AbstractAuthModuleProvider,
|
||||||
InjectManager,
|
InjectManager,
|
||||||
InjectTransactionManager,
|
InjectTransactionManager,
|
||||||
MedusaContext,
|
MedusaContext,
|
||||||
@@ -30,7 +30,7 @@ import {
|
|||||||
FilterableAuthProviderProps,
|
FilterableAuthProviderProps,
|
||||||
FilterableAuthUserProps,
|
FilterableAuthUserProps,
|
||||||
UpdateAuthUserDTO,
|
UpdateAuthUserDTO,
|
||||||
} from "@medusajs/types/dist/authentication/common"
|
} from "@medusajs/types"
|
||||||
import { ServiceTypes } from "@types"
|
import { ServiceTypes } from "@types"
|
||||||
|
|
||||||
type InjectedDependencies = {
|
type InjectedDependencies = {
|
||||||
@@ -39,10 +39,10 @@ type InjectedDependencies = {
|
|||||||
authProviderService: AuthProviderService<any>
|
authProviderService: AuthProviderService<any>
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class AuthenticationModuleService<
|
export default class AuthModuleService<
|
||||||
TAuthUser extends AuthUser = AuthUser,
|
TAuthUser extends AuthUser = AuthUser,
|
||||||
TAuthProvider extends AuthProvider = AuthProvider
|
TAuthProvider extends AuthProvider = AuthProvider
|
||||||
> implements AuthenticationTypes.IAuthenticationModuleService
|
> implements AuthTypes.IAuthModuleService
|
||||||
{
|
{
|
||||||
__joinerConfig(): ModuleJoinerConfig {
|
__joinerConfig(): ModuleJoinerConfig {
|
||||||
return joinerConfig
|
return joinerConfig
|
||||||
@@ -83,7 +83,7 @@ export default class AuthenticationModuleService<
|
|||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
|
|
||||||
return await this.baseRepository_.serialize<AuthenticationTypes.AuthProviderDTO>(
|
return await this.baseRepository_.serialize<AuthTypes.AuthProviderDTO>(
|
||||||
authProvider,
|
authProvider,
|
||||||
{ populate: true }
|
{ populate: true }
|
||||||
)
|
)
|
||||||
@@ -101,7 +101,7 @@ export default class AuthenticationModuleService<
|
|||||||
)
|
)
|
||||||
|
|
||||||
return await this.baseRepository_.serialize<
|
return await this.baseRepository_.serialize<
|
||||||
AuthenticationTypes.AuthProviderDTO[]
|
AuthTypes.AuthProviderDTO[]
|
||||||
>(authProviders, { populate: true })
|
>(authProviders, { populate: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ export default class AuthenticationModuleService<
|
|||||||
filters: FilterableAuthProviderProps = {},
|
filters: FilterableAuthProviderProps = {},
|
||||||
config: FindConfig<AuthProviderDTO>,
|
config: FindConfig<AuthProviderDTO>,
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<[AuthenticationTypes.AuthProviderDTO[], number]> {
|
): Promise<[AuthTypes.AuthProviderDTO[], number]> {
|
||||||
const [authProviders, count] = await this.authProviderService_.listAndCount(
|
const [authProviders, count] = await this.authProviderService_.listAndCount(
|
||||||
filters,
|
filters,
|
||||||
config,
|
config,
|
||||||
@@ -119,7 +119,7 @@ export default class AuthenticationModuleService<
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
await this.baseRepository_.serialize<
|
await this.baseRepository_.serialize<
|
||||||
AuthenticationTypes.AuthProviderDTO[]
|
AuthTypes.AuthProviderDTO[]
|
||||||
>(authProviders, { populate: true }),
|
>(authProviders, { populate: true }),
|
||||||
count,
|
count,
|
||||||
]
|
]
|
||||||
@@ -140,14 +140,14 @@ export default class AuthenticationModuleService<
|
|||||||
data: CreateAuthProviderDTO | CreateAuthProviderDTO[],
|
data: CreateAuthProviderDTO | CreateAuthProviderDTO[],
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<
|
): Promise<
|
||||||
AuthenticationTypes.AuthProviderDTO | AuthenticationTypes.AuthProviderDTO[]
|
AuthTypes.AuthProviderDTO | AuthTypes.AuthProviderDTO[]
|
||||||
> {
|
> {
|
||||||
const input = Array.isArray(data) ? data : [data]
|
const input = Array.isArray(data) ? data : [data]
|
||||||
|
|
||||||
const providers = await this.createAuthProviders_(input, sharedContext)
|
const providers = await this.createAuthProviders_(input, sharedContext)
|
||||||
|
|
||||||
const serializedProviders = await this.baseRepository_.serialize<
|
const serializedProviders = await this.baseRepository_.serialize<
|
||||||
AuthenticationTypes.AuthProviderDTO[]
|
AuthTypes.AuthProviderDTO[]
|
||||||
>(providers, {
|
>(providers, {
|
||||||
populate: true,
|
populate: true,
|
||||||
})
|
})
|
||||||
@@ -164,29 +164,29 @@ export default class AuthenticationModuleService<
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateAuthProvider(
|
updateAuthProvider(
|
||||||
data: AuthenticationTypes.UpdateAuthProviderDTO[],
|
data: AuthTypes.UpdateAuthProviderDTO[],
|
||||||
sharedContext?: Context
|
sharedContext?: Context
|
||||||
): Promise<AuthProviderDTO[]>
|
): Promise<AuthProviderDTO[]>
|
||||||
updateAuthProvider(
|
updateAuthProvider(
|
||||||
data: AuthenticationTypes.UpdateAuthProviderDTO,
|
data: AuthTypes.UpdateAuthProviderDTO,
|
||||||
sharedContext?: Context
|
sharedContext?: Context
|
||||||
): Promise<AuthProviderDTO>
|
): Promise<AuthProviderDTO>
|
||||||
|
|
||||||
@InjectManager("baseRepository_")
|
@InjectManager("baseRepository_")
|
||||||
async updateAuthProvider(
|
async updateAuthProvider(
|
||||||
data:
|
data:
|
||||||
| AuthenticationTypes.UpdateAuthProviderDTO[]
|
| AuthTypes.UpdateAuthProviderDTO[]
|
||||||
| AuthenticationTypes.UpdateAuthProviderDTO,
|
| AuthTypes.UpdateAuthProviderDTO,
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<
|
): Promise<
|
||||||
AuthenticationTypes.AuthProviderDTO | AuthenticationTypes.AuthProviderDTO[]
|
AuthTypes.AuthProviderDTO | AuthTypes.AuthProviderDTO[]
|
||||||
> {
|
> {
|
||||||
const input = Array.isArray(data) ? data : [data]
|
const input = Array.isArray(data) ? data : [data]
|
||||||
|
|
||||||
const providers = await this.updateAuthProvider_(input, sharedContext)
|
const providers = await this.updateAuthProvider_(input, sharedContext)
|
||||||
|
|
||||||
const serializedProviders = await this.baseRepository_.serialize<
|
const serializedProviders = await this.baseRepository_.serialize<
|
||||||
AuthenticationTypes.AuthProviderDTO[]
|
AuthTypes.AuthProviderDTO[]
|
||||||
>(providers, {
|
>(providers, {
|
||||||
populate: true,
|
populate: true,
|
||||||
})
|
})
|
||||||
@@ -195,7 +195,7 @@ export default class AuthenticationModuleService<
|
|||||||
}
|
}
|
||||||
|
|
||||||
async updateAuthProvider_(
|
async updateAuthProvider_(
|
||||||
data: AuthenticationTypes.UpdateAuthProviderDTO[],
|
data: AuthTypes.UpdateAuthProviderDTO[],
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<TAuthProvider[]> {
|
): Promise<TAuthProvider[]> {
|
||||||
return await this.authProviderService_.update(data, sharedContext)
|
return await this.authProviderService_.update(data, sharedContext)
|
||||||
@@ -221,7 +221,7 @@ export default class AuthenticationModuleService<
|
|||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
|
|
||||||
return await this.baseRepository_.serialize<AuthenticationTypes.AuthUserDTO>(
|
return await this.baseRepository_.serialize<AuthTypes.AuthUserDTO>(
|
||||||
authUser,
|
authUser,
|
||||||
{
|
{
|
||||||
exclude: ["password_hash"],
|
exclude: ["password_hash"],
|
||||||
@@ -242,7 +242,7 @@ export default class AuthenticationModuleService<
|
|||||||
)
|
)
|
||||||
|
|
||||||
return await this.baseRepository_.serialize<
|
return await this.baseRepository_.serialize<
|
||||||
AuthenticationTypes.AuthUserDTO[]
|
AuthTypes.AuthUserDTO[]
|
||||||
>(authUsers, {
|
>(authUsers, {
|
||||||
populate: true,
|
populate: true,
|
||||||
})
|
})
|
||||||
@@ -261,7 +261,7 @@ export default class AuthenticationModuleService<
|
|||||||
)
|
)
|
||||||
|
|
||||||
return [
|
return [
|
||||||
await this.baseRepository_.serialize<AuthenticationTypes.AuthUserDTO[]>(
|
await this.baseRepository_.serialize<AuthTypes.AuthUserDTO[]>(
|
||||||
authUsers,
|
authUsers,
|
||||||
{
|
{
|
||||||
populate: true,
|
populate: true,
|
||||||
@@ -285,14 +285,14 @@ export default class AuthenticationModuleService<
|
|||||||
data: CreateAuthUserDTO[] | CreateAuthUserDTO,
|
data: CreateAuthUserDTO[] | CreateAuthUserDTO,
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<
|
): Promise<
|
||||||
AuthenticationTypes.AuthUserDTO | AuthenticationTypes.AuthUserDTO[]
|
AuthTypes.AuthUserDTO | AuthTypes.AuthUserDTO[]
|
||||||
> {
|
> {
|
||||||
const input = Array.isArray(data) ? data : [data]
|
const input = Array.isArray(data) ? data : [data]
|
||||||
|
|
||||||
const authUsers = await this.createAuthUsers_(input, sharedContext)
|
const authUsers = await this.createAuthUsers_(input, sharedContext)
|
||||||
|
|
||||||
const serializedUsers = await this.baseRepository_.serialize<
|
const serializedUsers = await this.baseRepository_.serialize<
|
||||||
AuthenticationTypes.AuthUserDTO[]
|
AuthTypes.AuthUserDTO[]
|
||||||
>(authUsers, {
|
>(authUsers, {
|
||||||
populate: true,
|
populate: true,
|
||||||
})
|
})
|
||||||
@@ -322,14 +322,14 @@ export default class AuthenticationModuleService<
|
|||||||
data: UpdateAuthUserDTO | UpdateAuthUserDTO[],
|
data: UpdateAuthUserDTO | UpdateAuthUserDTO[],
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<
|
): Promise<
|
||||||
AuthenticationTypes.AuthUserDTO | AuthenticationTypes.AuthUserDTO[]
|
AuthTypes.AuthUserDTO | AuthTypes.AuthUserDTO[]
|
||||||
> {
|
> {
|
||||||
const input = Array.isArray(data) ? data : [data]
|
const input = Array.isArray(data) ? data : [data]
|
||||||
|
|
||||||
const updatedUsers = await this.updateAuthUsers_(input, sharedContext)
|
const updatedUsers = await this.updateAuthUsers_(input, sharedContext)
|
||||||
|
|
||||||
const serializedUsers = await this.baseRepository_.serialize<
|
const serializedUsers = await this.baseRepository_.serialize<
|
||||||
AuthenticationTypes.AuthUserDTO[]
|
AuthTypes.AuthUserDTO[]
|
||||||
>(updatedUsers, {
|
>(updatedUsers, {
|
||||||
populate: true,
|
populate: true,
|
||||||
})
|
})
|
||||||
@@ -356,8 +356,8 @@ export default class AuthenticationModuleService<
|
|||||||
protected getRegisteredAuthenticationProvider(
|
protected getRegisteredAuthenticationProvider(
|
||||||
provider: string,
|
provider: string,
|
||||||
{ scope }: AuthenticationInput
|
{ scope }: AuthenticationInput
|
||||||
): AbstractAuthenticationModuleProvider {
|
): AbstractAuthModuleProvider {
|
||||||
let containerProvider: AbstractAuthenticationModuleProvider
|
let containerProvider: AbstractAuthModuleProvider
|
||||||
try {
|
try {
|
||||||
containerProvider = this.__container__[`auth_provider_${provider}`]
|
containerProvider = this.__container__[`auth_provider_${provider}`]
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
File renamed without changes.
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
import { AuthenticationTypes, Context, DAL, FindConfig } from "@medusajs/types"
|
import { AuthTypes, Context, DAL, FindConfig } from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
InjectManager,
|
InjectManager,
|
||||||
MedusaContext,
|
MedusaContext,
|
||||||
@@ -29,7 +29,7 @@ export default class AuthUserService<
|
|||||||
|
|
||||||
@InjectManager("authUserRepository_")
|
@InjectManager("authUserRepository_")
|
||||||
async retrieveByProviderAndEntityId<
|
async retrieveByProviderAndEntityId<
|
||||||
TEntityMethod = AuthenticationTypes.AuthUserDTO
|
TEntityMethod = AuthTypes.AuthUserDTO
|
||||||
>(
|
>(
|
||||||
entityId: string,
|
entityId: string,
|
||||||
provider: string,
|
provider: string,
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
export { default as AuthenticationModuleService } from "./authentication-module"
|
export { default as AuthModuleService } from "./auth-module"
|
||||||
export { default as AuthProviderService } from "./auth-provider"
|
export { default as AuthProviderService } from "./auth-provider"
|
||||||
export { default as AuthUserService } from "./auth-user"
|
export { default as AuthUserService } from "./auth-user"
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,3 +0,0 @@
|
|||||||
# Authentication Module
|
|
||||||
|
|
||||||
The Authentication Module is Medusa’s authentication engine engine. It provides functions to authenticate users through identity providers and store metadata about users that can be used for authorization purposes.
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
if (typeof process.env.DB_TEMP_NAME === "undefined") {
|
|
||||||
const tempName = parseInt(process.env.JEST_WORKER_ID || "1")
|
|
||||||
process.env.DB_TEMP_NAME = `medusa-authentication-integration-${tempName}`
|
|
||||||
}
|
|
||||||
|
|
||||||
process.env.MEDUSA_AUTHENTICATION_DB_SCHEMA = "public"
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
export { default as UsernamePasswordProvider } from "./username-password"
|
|
||||||
export { default as GoogleProvider } from "./google"
|
|
||||||
@@ -15,7 +15,7 @@ export enum Modules {
|
|||||||
PRODUCT = "productService",
|
PRODUCT = "productService",
|
||||||
PRICING = "pricingService",
|
PRICING = "pricingService",
|
||||||
PROMOTION = "promotion",
|
PROMOTION = "promotion",
|
||||||
AUTHENTICATION = "authentication",
|
AUTH = "auth",
|
||||||
WORKFLOW_ENGINE = "workflows",
|
WORKFLOW_ENGINE = "workflows",
|
||||||
SALES_CHANNEL = "salesChannel",
|
SALES_CHANNEL = "salesChannel",
|
||||||
CART = "cart",
|
CART = "cart",
|
||||||
@@ -31,7 +31,7 @@ export enum ModuleRegistrationName {
|
|||||||
PRODUCT = "productModuleService",
|
PRODUCT = "productModuleService",
|
||||||
PRICING = "pricingModuleService",
|
PRICING = "pricingModuleService",
|
||||||
PROMOTION = "promotionModuleService",
|
PROMOTION = "promotionModuleService",
|
||||||
AUTHENTICATION = "authenticationModuleService",
|
AUTH = "authModuleService",
|
||||||
WORKFLOW_ENGINE = "workflowsModuleService",
|
WORKFLOW_ENGINE = "workflowsModuleService",
|
||||||
SALES_CHANNEL = "salesChannelModuleService",
|
SALES_CHANNEL = "salesChannelModuleService",
|
||||||
CART = "cartModuleService",
|
CART = "cartModuleService",
|
||||||
@@ -48,7 +48,7 @@ export const MODULE_PACKAGE_NAMES = {
|
|||||||
[Modules.CACHE]: "@medusajs/cache-inmemory",
|
[Modules.CACHE]: "@medusajs/cache-inmemory",
|
||||||
[Modules.PRICING]: "@medusajs/pricing",
|
[Modules.PRICING]: "@medusajs/pricing",
|
||||||
[Modules.PROMOTION]: "@medusajs/promotion",
|
[Modules.PROMOTION]: "@medusajs/promotion",
|
||||||
[Modules.AUTHENTICATION]: "@medusajs/authentication",
|
[Modules.AUTH]: "@medusajs/auth",
|
||||||
[Modules.WORKFLOW_ENGINE]: "@medusajs/workflow-engine-inmemory",
|
[Modules.WORKFLOW_ENGINE]: "@medusajs/workflow-engine-inmemory",
|
||||||
[Modules.SALES_CHANNEL]: "@medusajs/sales-channel",
|
[Modules.SALES_CHANNEL]: "@medusajs/sales-channel",
|
||||||
[Modules.CART]: "@medusajs/cart",
|
[Modules.CART]: "@medusajs/cart",
|
||||||
@@ -157,11 +157,11 @@ export const ModulesDefinition: { [key: string | Modules]: ModuleDefinition } =
|
|||||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
[Modules.AUTHENTICATION]: {
|
[Modules.AUTH]: {
|
||||||
key: Modules.AUTHENTICATION,
|
key: Modules.AUTH,
|
||||||
registrationName: ModuleRegistrationName.AUTHENTICATION,
|
registrationName: ModuleRegistrationName.AUTH,
|
||||||
defaultPackage: false,
|
defaultPackage: false,
|
||||||
label: upperCaseFirst(ModuleRegistrationName.AUTHENTICATION),
|
label: upperCaseFirst(ModuleRegistrationName.AUTH),
|
||||||
isRequired: false,
|
isRequired: false,
|
||||||
canOverride: true,
|
canOverride: true,
|
||||||
isQueryable: true,
|
isQueryable: true,
|
||||||
|
|||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,22 @@
|
|||||||
|
export type AuthenticationResponse = {
|
||||||
|
success: boolean
|
||||||
|
authUser?: any
|
||||||
|
error?: string
|
||||||
|
location?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AuthModuleProviderConfig = {
|
||||||
|
name: string
|
||||||
|
scopes: Record<string, AuthProviderScope>
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AuthProviderScope = { domain?: string } & Record<string, string>
|
||||||
|
|
||||||
|
export type AuthenticationInput = {
|
||||||
|
connection: { encrypted: boolean }
|
||||||
|
url: string
|
||||||
|
headers: Record<string, string>
|
||||||
|
query: Record<string, string>
|
||||||
|
body: Record<string, string>
|
||||||
|
scope: string
|
||||||
|
}
|
||||||
File renamed without changes.
@@ -15,7 +15,7 @@ import { Context } from "../shared-context"
|
|||||||
import { FindConfig } from "../common"
|
import { FindConfig } from "../common"
|
||||||
import { IModuleService } from "../modules-sdk"
|
import { IModuleService } from "../modules-sdk"
|
||||||
|
|
||||||
export interface IAuthenticationModuleService extends IModuleService {
|
export interface IAuthModuleService extends IModuleService {
|
||||||
authenticate(
|
authenticate(
|
||||||
provider: string,
|
provider: string,
|
||||||
providerData: AuthenticationInput
|
providerData: AuthenticationInput
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
export * as AuthenticationTypes from "./authentication"
|
export * as AuthTypes from "./auth"
|
||||||
export * as CacheTypes from "./cache"
|
export * as CacheTypes from "./cache"
|
||||||
export * as CartTypes from "./cart"
|
export * as CartTypes from "./cart"
|
||||||
export * as CommonTypes from "./common"
|
export * as CommonTypes from "./common"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
export * from "./address"
|
export * from "./address"
|
||||||
export * from "./authentication"
|
export * from "./auth"
|
||||||
export * from "./bundles"
|
export * from "./bundles"
|
||||||
export * from "./cache"
|
export * from "./cache"
|
||||||
export * from "./cart"
|
export * from "./cart"
|
||||||
|
|||||||
+3
-2
@@ -1,7 +1,8 @@
|
|||||||
import { AuthenticationResponse, AuthProviderScope } from "@medusajs/types"
|
import { AuthProviderScope, AuthenticationResponse } from "@medusajs/types"
|
||||||
|
|
||||||
import { MedusaError } from "../common"
|
import { MedusaError } from "../common"
|
||||||
|
|
||||||
export abstract class AbstractAuthenticationModuleProvider {
|
export abstract class AbstractAuthModuleProvider {
|
||||||
public static PROVIDER: string
|
public static PROVIDER: string
|
||||||
public static DISPLAY_NAME: string
|
public static DISPLAY_NAME: string
|
||||||
protected readonly scopes_: Record<string, AuthProviderScope>
|
protected readonly scopes_: Record<string, AuthProviderScope>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export * from "./abstract-auth-provider"
|
||||||
@@ -1 +0,0 @@
|
|||||||
export * from "./abstract-authentication-provider"
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
export * from "./authentication"
|
export * from "./auth"
|
||||||
export * from "./bundles"
|
export * from "./bundles"
|
||||||
export * from "./common"
|
export * from "./common"
|
||||||
export * from "./dal"
|
export * from "./dal"
|
||||||
|
|||||||
@@ -7889,9 +7889,9 @@ __metadata:
|
|||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
|
|
||||||
"@medusajs/authentication@workspace:packages/authentication":
|
"@medusajs/auth@workspace:packages/auth":
|
||||||
version: 0.0.0-use.local
|
version: 0.0.0-use.local
|
||||||
resolution: "@medusajs/authentication@workspace:packages/authentication"
|
resolution: "@medusajs/auth@workspace:packages/auth"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@medusajs/modules-sdk": ^1.12.7
|
"@medusajs/modules-sdk": ^1.12.7
|
||||||
"@medusajs/types": ^1.11.11
|
"@medusajs/types": ^1.11.11
|
||||||
@@ -7915,7 +7915,7 @@ __metadata:
|
|||||||
tsc-alias: ^1.8.6
|
tsc-alias: ^1.8.6
|
||||||
typescript: ^5.1.6
|
typescript: ^5.1.6
|
||||||
bin:
|
bin:
|
||||||
medusa-authentication-seed: dist/scripts/bin/run-seed.js
|
medusa-auth-seed: dist/scripts/bin/run-seed.js
|
||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user