-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat(auth): added new array-like structure * bump: simplify the array extraction Co-authored-by: Adrien de Peretti <[email protected]> * bump(auth): lint fix * fix(auth): iteration over auth options --------- Co-authored-by: Adrien de Peretti <[email protected]>
- Loading branch information
1 parent
6f0a633
commit 65e7439
Showing
49 changed files
with
1,164 additions
and
899 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import { ConfigModule, MedusaContainer } from '@medusajs/medusa/dist/types/global'; | ||
import { Auth0AdminStrategy } from '../../admin'; | ||
import { AUTH_PROVIDER_KEY } from '../../../../types'; | ||
import { Auth0Options, AUTH0_ADMIN_STRATEGY_NAME, Profile, ExtraParams } from '../../types'; | ||
import { AUTH_PROVIDER_KEY, IStrategy } from '../../../../types'; | ||
import { AUTH0_ADMIN_STRATEGY_NAME, Auth0Options, ExtraParams } from '../../types'; | ||
import { Profile } from 'passport-auth0'; | ||
import { getAuth0AdminStrategy } from '../../admin'; | ||
|
||
describe('Auth0 admin strategy verify callback', function () { | ||
const existsEmail = '[email protected]'; | ||
|
@@ -12,9 +13,9 @@ describe('Auth0 admin strategy verify callback', function () { | |
let req: Request; | ||
let accessToken: string; | ||
let refreshToken: string; | ||
let profile: Profile; | ||
let profile: Partial<Profile>; | ||
let extraParams: ExtraParams; | ||
let auth0AdminStrategy: Auth0AdminStrategy; | ||
let auth0AdminStrategy: IStrategy; | ||
|
||
beforeEach(() => { | ||
profile = { | ||
|
@@ -38,7 +39,7 @@ describe('Auth0 admin strategy verify callback', function () { | |
return { | ||
id: 'test2', | ||
metadata: { | ||
[AUTH_PROVIDER_KEY]: AUTH0_ADMIN_STRATEGY_NAME, | ||
[AUTH_PROVIDER_KEY]: AUTH0_ADMIN_STRATEGY_NAME + '_test', | ||
}, | ||
}; | ||
} | ||
|
@@ -64,6 +65,7 @@ describe('Auth0 admin strategy verify callback', function () { | |
|
||
describe('when strict is set to admin', function () { | ||
beforeEach(() => { | ||
const Auth0AdminStrategy = getAuth0AdminStrategy('test'); | ||
auth0AdminStrategy = new Auth0AdminStrategy( | ||
container, | ||
{} as ConfigModule, | ||
|
@@ -130,6 +132,7 @@ describe('Auth0 admin strategy verify callback', function () { | |
|
||
describe('when strict is set for store only', function () { | ||
beforeEach(() => { | ||
const Auth0AdminStrategy = getAuth0AdminStrategy('test'); | ||
auth0AdminStrategy = new Auth0AdminStrategy( | ||
container, | ||
{} as ConfigModule, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import { Auth0StoreStrategy } from '../../store'; | ||
import { ConfigModule, MedusaContainer } from '@medusajs/medusa/dist/types/global'; | ||
import { AUTH_PROVIDER_KEY, CUSTOMER_METADATA_KEY } from '../../../../types'; | ||
import { Auth0Options, AUTH0_STORE_STRATEGY_NAME, Profile, ExtraParams } from '../../types'; | ||
import { AUTH_PROVIDER_KEY, CUSTOMER_METADATA_KEY, IStrategy } from '../../../../types'; | ||
import { AUTH0_STORE_STRATEGY_NAME, Auth0Options, ExtraParams } from '../../types'; | ||
import { Profile } from 'passport-auth0'; | ||
import { getAuth0StoreStrategy } from '../../store'; | ||
|
||
describe('Auth0 store strategy verify callback', function () { | ||
const existsEmail = '[email protected]'; | ||
|
@@ -13,9 +14,9 @@ describe('Auth0 store strategy verify callback', function () { | |
let req: Request; | ||
let accessToken: string; | ||
let refreshToken: string; | ||
let profile: Profile; | ||
let profile: Partial<Profile>; | ||
let extraParams: ExtraParams; | ||
let auth0StoreStrategy: Auth0StoreStrategy; | ||
let auth0StoreStrategy: IStrategy; | ||
let updateFn; | ||
let createFn; | ||
|
||
|
@@ -67,7 +68,7 @@ describe('Auth0 store strategy verify callback', function () { | |
id: 'test3', | ||
metadata: { | ||
[CUSTOMER_METADATA_KEY]: true, | ||
[AUTH_PROVIDER_KEY]: AUTH0_STORE_STRATEGY_NAME, | ||
[AUTH_PROVIDER_KEY]: AUTH0_STORE_STRATEGY_NAME + '_test', | ||
}, | ||
}; | ||
} | ||
|
@@ -94,6 +95,7 @@ describe('Auth0 store strategy verify callback', function () { | |
|
||
describe('when strict is set to store', function () { | ||
beforeEach(() => { | ||
const Auth0StoreStrategy = getAuth0StoreStrategy('test'); | ||
auth0StoreStrategy = new Auth0StoreStrategy( | ||
container, | ||
{} as ConfigModule, | ||
|
@@ -183,6 +185,7 @@ describe('Auth0 store strategy verify callback', function () { | |
|
||
describe('when strict is set to admin', function () { | ||
beforeEach(() => { | ||
const Auth0StoreStrategy = getAuth0StoreStrategy('test'); | ||
auth0StoreStrategy = new Auth0StoreStrategy( | ||
container, | ||
{} as ConfigModule, | ||
|
102 changes: 54 additions & 48 deletions
102
packages/medusa-plugin-auth/src/auth-strategies/auth0/admin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 19 additions & 15 deletions
34
packages/medusa-plugin-auth/src/auth-strategies/auth0/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,38 @@ | ||
import { ConfigModule, MedusaContainer } from '@medusajs/medusa/dist/types/global'; | ||
import { AuthOptions, StrategyExport } from '../../types'; | ||
import { StrategyExport } from '../../types'; | ||
import { Router } from 'express'; | ||
import { getAuth0AdminAuthRouter, Auth0AdminStrategy } from './admin'; | ||
import { getAuth0StoreAuthRouter, Auth0StoreStrategy } from './store'; | ||
import { getAuth0AdminAuthRouter, getAuth0AdminStrategy } from './admin'; | ||
import { getAuth0StoreAuthRouter, getAuth0StoreStrategy } from './store'; | ||
import { Auth0Options } from './types'; | ||
|
||
export * from './admin'; | ||
export * from './store'; | ||
export * from './types'; | ||
|
||
export default { | ||
load: (container: MedusaContainer, configModule: ConfigModule, options: AuthOptions): void => { | ||
if (options.auth0?.admin) { | ||
new Auth0AdminStrategy(container, configModule, options.auth0, options.strict); | ||
load: (container, configModule, option): void => { | ||
const id = option.identifier ?? option.type; | ||
if (option.admin) { | ||
const Clazz = getAuth0AdminStrategy(id); | ||
new Clazz(container, configModule, option, option.strict); | ||
} | ||
|
||
if (options.auth0?.store) { | ||
new Auth0StoreStrategy(container, configModule, options.auth0, options.strict); | ||
if (option.store) { | ||
const Clazz = getAuth0StoreStrategy(id); | ||
new Clazz(container, configModule, option, option.strict); | ||
} | ||
}, | ||
getRouter: (configModule: ConfigModule, options: AuthOptions): Router[] => { | ||
getRouter: (configModule, option): Router[] => { | ||
const routers = []; | ||
const id = option.identifier ?? option.type; | ||
|
||
if (options.auth0?.admin) { | ||
routers.push(getAuth0AdminAuthRouter(options.auth0, configModule)); | ||
if (option.admin) { | ||
routers.push(getAuth0AdminAuthRouter(id, option, configModule)); | ||
} | ||
|
||
if (options.auth0?.store) { | ||
routers.push(getAuth0StoreAuthRouter(options.auth0, configModule)); | ||
if (option.store) { | ||
routers.push(getAuth0StoreAuthRouter(id, option, configModule)); | ||
} | ||
|
||
return routers; | ||
}, | ||
} as StrategyExport; | ||
} as StrategyExport<Auth0Options>; |
Oops, something went wrong.
65e7439
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
medusa-plugins – ./
medusa-plugins-adrien2p.vercel.app
medusa-plugins.vercel.app
medusa-plugins-git-main-adrien2p.vercel.app