feat(auth): add authentication endpoints (#6265)

**What**
- Add authentication endpoints: 
  - `/auth/[scope]/[provider]` 
  - `/auth/[scope]/[provider]/callback`
- update authenticate-middleware handler
- Add scope field to user
- Add unique constraint on scope and entity_id

note: there's still some remaining work related to jwt auth to be handled, this is mainly focussed on session auth with endpoints



Co-authored-by: Sebastian Rindom <7554214+srindom@users.noreply.github.com>
This commit is contained in:
Philip KorsholmandSebastian Rindom authored and GitHub committed 2024-02-02 10:45:32 +00:00
1 parent 061c449179
commit 9fda6a6824
31 files changed
+302 -146

No files matched your search

@@ -1,6 +1,6 @@
import { AuthenticationInput, IAuthModuleService } from "@medusajs/types"
import { MedusaModule, Modules } from "@medusajs/modules-sdk"
import { IAuthModuleService } from "@medusajs/types"
import { MikroOrmWrapper } from "../../../utils"
import Scrypt from "scrypt-kdf"
import { SqlEntityManager } from "@mikro-orm/postgresql"
@@ -62,6 +62,7 @@ describe("AuthModuleService - AuthProvider", () => {
{
provider: "emailpass",
entity_id: email,
scope: "store",
provider_metadata: {
password: passwordHash,
},
@@ -73,8 +74,8 @@ describe("AuthModuleService - AuthProvider", () => {
email: "test@test.com",
password: password,
},
scope: "store",
})
authScope: "store",
} as any)
expect(res).toEqual({
success: true,
@@ -92,8 +93,8 @@ describe("AuthModuleService - AuthProvider", () => {
const res = await service.authenticate("emailpass", {
body: { email: "test@test.com" },
scope: "store",
})
authScope: "store",
} as any)
expect(res).toEqual({
success: false,
@@ -106,8 +107,8 @@ describe("AuthModuleService - AuthProvider", () => {
const res = await service.authenticate("emailpass", {
body: { password: "supersecret" },
scope: "store",
})
authScope: "store",
} as any)
expect(res).toEqual({
success: false,
@@ -127,6 +128,7 @@ describe("AuthModuleService - AuthProvider", () => {
// Add authenticated user
{
provider: "emailpass",
scope: "store",
entity_id: email,
provider_metadata: {
password_hash: passwordHash,
@@ -139,8 +141,8 @@ describe("AuthModuleService - AuthProvider", () => {
email: "test@test.com",
password: "password",
},
scope: "store",
})
authScope: "store",
} as any)
expect(res).toEqual({
success: false,