Skip to content

Commit

Permalink
feat: add support for strict options
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien2p committed Jun 13, 2023
1 parent 79872de commit 6e34220
Show file tree
Hide file tree
Showing 21 changed files with 278 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export class Auth0AdminStrategy extends PassportStrategy(Auth0Strategy, AUTH0_AD
constructor(
protected readonly container: MedusaContainer,
protected readonly configModule: ConfigModule,
protected readonly strategyOptions: Auth0Options
protected readonly strategyOptions: Auth0Options,
protected readonly strictOptions: { admin_strict: boolean; strict: boolean }
) {
super({
domain: strategyOptions.auth0Domain,
Expand Down Expand Up @@ -47,6 +48,7 @@ export class Auth0AdminStrategy extends PassportStrategy(Auth0Strategy, AUTH0_AD
const validateRes = await validateAdminCallback(profile, {
container: this.container,
strategyErrorIdentifier: 'auth0',
strict: this.strictOptions.admin_strict ?? this.strictOptions.strict,
});
return {
...validateRes,
Expand Down
10 changes: 8 additions & 2 deletions packages/medusa-plugin-auth/src/auth-strategies/auth0/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ export * from './types';
export default {
load: (container: MedusaContainer, configModule: ConfigModule, options: AuthOptions): void => {
if (options.auth0?.admin) {
new Auth0AdminStrategy(container, configModule, options.auth0);
new Auth0AdminStrategy(container, configModule, options.auth0, {
admin_strict: options.admin_strict,
strict: options.strict,
});
}

if (options.auth0?.store) {
new Auth0StoreStrategy(container, configModule, options.auth0);
new Auth0StoreStrategy(container, configModule, options.auth0, {
store_strict: options.store_strict,
strict: options.strict,
});
}
},
getRouter: (configModule: ConfigModule, options: AuthOptions): Router[] => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export class Auth0StoreStrategy extends PassportStrategy(Auth0Strategy, AUTH0_ST
constructor(
protected readonly container: MedusaContainer,
protected readonly configModule: ConfigModule,
protected readonly strategyOptions: Auth0Options
protected readonly strategyOptions: Auth0Options,
protected readonly strictOptions: { store_strict: boolean; strict: boolean }
) {
super({
domain: strategyOptions.auth0Domain,
Expand Down Expand Up @@ -44,9 +45,11 @@ export class Auth0StoreStrategy extends PassportStrategy(Auth0Strategy, AUTH0_ST
accessToken,
};
}

const validateRes = await validateStoreCallback(profile, {
container: this.container,
strategyErrorIdentifier: 'auth0',
strict: this.strictOptions.store_strict ?? this.strictOptions.strict,
});
return {
...validateRes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export class AzureAdminStrategy extends PassportStrategy(AzureStrategy, AZURE_AD
constructor(
protected readonly container: MedusaContainer,
protected readonly configModule: ConfigModule,
protected readonly strategyOptions: AzureAuthOptions
protected readonly strategyOptions: AzureAuthOptions,
protected readonly strictOptions: { admin_strict: boolean; strict: boolean }
) {
super({
identityMetadata: strategyOptions.admin.identityMetadata,
Expand All @@ -36,9 +37,11 @@ export class AzureAdminStrategy extends PassportStrategy(AzureStrategy, AZURE_AD
emails: [{ value: profile?.upn }],
name: { givenName: profile?.name?.givenName, familyName: profile?.name?.familyName },
};

return await validateAdminCallback(authprofile, {
container: this.container,
strategyErrorIdentifier: 'azure_oidc',
strict: this.strictOptions.admin_strict ?? this.strictOptions.strict,
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ export * from './store';
export default {
load: (container: MedusaContainer, configModule: ConfigModule, options: AuthOptions): void => {
if (options.azure_oidc?.admin) {
new AzureAdminStrategy(container, configModule, options.azure_oidc);
new AzureAdminStrategy(container, configModule, options.azure_oidc,{
admin_strict: options.admin_strict,
strict: options.strict,
});
}

if (options.azure_oidc?.store) {
new AzureStoreStrategy(container, configModule, options.azure_oidc);
new AzureStoreStrategy(container, configModule, options.azure_oidc, {
store_strict: options.store_strict,
strict: options.strict,
});
}
},
getRouter: (configModule: ConfigModule, options: AuthOptions): Router[] => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export class AzureStoreStrategy extends PassportStrategy(AzureStrategy, AZURE_ST
constructor(
protected readonly container: MedusaContainer,
protected readonly configModule: ConfigModule,
protected readonly strategyOptions: AzureAuthOptions
protected readonly strategyOptions: AzureAuthOptions,
protected readonly strictOptions: { store_strict: boolean; strict: boolean }
) {
super({
identityMetadata: strategyOptions.store.identityMetadata,
Expand All @@ -36,9 +37,11 @@ export class AzureStoreStrategy extends PassportStrategy(AzureStrategy, AZURE_ST
emails: [{ value: profile?.upn }],
name: { givenName: profile?.name?.givenName, familyName: profile?.name?.familyName },
};

return await validateStoreCallback(authprofile, {
container: this.container,
strategyErrorIdentifier: 'azure_oidc',
strict: this.strictOptions.store_strict ?? this.strictOptions.strict,
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export class FacebookAdminStrategy extends PassportStrategy(FacebookStrategy, FA
constructor(
protected readonly container: MedusaContainer,
protected readonly configModule: ConfigModule,
protected readonly strategyOptions: FacebookAuthOptions
protected readonly strategyOptions: FacebookAuthOptions,
protected readonly strictOptions: { admin_strict: boolean; strict: boolean }
) {
super({
clientID: strategyOptions.clientID,
Expand All @@ -36,7 +37,12 @@ export class FacebookAdminStrategy extends PassportStrategy(FacebookStrategy, FA
profile
);
}
return await validateAdminCallback(profile, { container: this.container, strategyErrorIdentifier: 'facebook' });

return await validateAdminCallback(profile, {
container: this.container,
strategyErrorIdentifier: 'facebook',
strict: this.strictOptions.admin_strict ?? this.strictOptions.strict,
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ export * from './types';
export default {
load: (container: MedusaContainer, configModule: ConfigModule, options: AuthOptions): void => {
if (options.facebook?.admin) {
new FacebookAdminStrategy(container, configModule, options.facebook);
new FacebookAdminStrategy(container, configModule, options.facebook, {
admin_strict: options.admin_strict,
strict: options.strict,
});
}

if (options.facebook?.store) {
new FacebookStoreStrategy(container, configModule, options.facebook);
new FacebookStoreStrategy(container, configModule, options.facebook, {
store_strict: options.store_strict,
strict: options.strict,
});
}
},
getRouter: (configModule: ConfigModule, options: AuthOptions): Router[] => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export class FacebookStoreStrategy extends PassportStrategy(FacebookStrategy, FA
constructor(
protected readonly container: MedusaContainer,
protected readonly configModule: ConfigModule,
protected readonly strategyOptions: FacebookAuthOptions
protected readonly strategyOptions: FacebookAuthOptions,
protected readonly strictOptions: { store_strict: boolean; strict: boolean }
) {
super({
clientID: strategyOptions.clientID,
Expand All @@ -36,7 +37,12 @@ export class FacebookStoreStrategy extends PassportStrategy(FacebookStrategy, FA
profile
);
}
return await validateStoreCallback(profile, { container: this.container, strategyErrorIdentifier: 'facebook' });

return await validateStoreCallback(profile, {
container: this.container,
strategyErrorIdentifier: 'facebook',
strict: this.strictOptions.store_strict ?? this.strictOptions.strict,
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export class FirebaseAdminStrategy extends PassportStrategy(FirebaseStrategy, FI
constructor(
protected readonly container: MedusaContainer,
protected readonly configModule: ConfigModule,
protected readonly strategyOptions: FirebaseAuthOptions
protected readonly strategyOptions: FirebaseAuthOptions,
protected readonly strictOptions: { admin_strict: boolean; strict: boolean }
) {
super({
jwtFromRequest: strategyOptions.store.jwtFromRequest ?? ExtractJwt.fromAuthHeaderAsBearerToken(),
Expand All @@ -26,7 +27,11 @@ export class FirebaseAdminStrategy extends PassportStrategy(FirebaseStrategy, FI
}

const profile: Profile = { emails: [{ value: decodedToken.email }] };
return await validateAdminCallback(profile, { container: this.container, strategyErrorIdentifier: 'firebase' });
return await validateAdminCallback(profile, {
container: this.container,
strategyErrorIdentifier: 'firebase',
strict: this.strictOptions.admin_strict ?? this.strictOptions.strict,
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ export default {
}

if (options.firebase?.admin) {
new FirebaseAdminStrategy(container, configModule, options.firebase);
new FirebaseAdminStrategy(container, configModule, options.firebase, {
admin_strict: options.admin_strict,
strict: options.strict,
});
}

if (options.firebase?.store) {
new FirebaseStoreStrategy(container, configModule, options.firebase);
new FirebaseStoreStrategy(container, configModule, options.firebase, {
store_strict: options.store_strict,
strict: options.strict,
});
}
},
getRouter: (configModule: ConfigModule, options: AuthOptions): Router[] => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export class FirebaseStoreStrategy extends PassportStrategy(FirebaseStrategy, FI
constructor(
protected readonly container: MedusaContainer,
protected readonly configModule: ConfigModule,
protected readonly strategyOptions: FirebaseAuthOptions
protected readonly strategyOptions: FirebaseAuthOptions,
protected readonly strictOptions: { store_strict: boolean; strict: boolean }
) {
super({
jwtFromRequest: strategyOptions.store.jwtFromRequest ?? ExtractJwt.fromAuthHeaderAsBearerToken(),
Expand All @@ -26,7 +27,11 @@ export class FirebaseStoreStrategy extends PassportStrategy(FirebaseStrategy, FI
}

const profile: Profile = { emails: [{ value: decodedToken.email }] };
return await validateStoreCallback(profile, { container: this.container, strategyErrorIdentifier: 'firebase' });
return await validateStoreCallback(profile, {
container: this.container,
strategyErrorIdentifier: 'firebase',
strict: this.strictOptions.store_strict ?? this.strictOptions.strict,
});
}
}

Expand Down
Loading

0 comments on commit 6e34220

Please sign in to comment.