medusa-plugin-auth-xponential
Version:
Social authentication plugin for medusajs 1.x
81 lines • 4.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAzureStoreStrategy = getAzureStoreStrategy;
exports.getAzureStoreAuthRouter = getAzureStoreAuthRouter;
const passport_azure_ad_1 = require("passport-azure-ad");
const Strategy_1 = require("../../core/passport/Strategy");
const types_1 = require("./types");
const auth_routes_builder_1 = require("../../core/passport/utils/auth-routes-builder");
const validate_callback_1 = require("../../core/validate-callback");
/**
* Return the azure store strategy
* @param id
*/
function getAzureStoreStrategy(id) {
const strategyName = `${types_1.AZURE_STORE_STRATEGY_NAME}_${id}`;
return class extends (0, Strategy_1.PassportStrategy)(passport_azure_ad_1.OIDCStrategy, strategyName) {
constructor(container, configModule, strategyOptions, strict) {
var _a, _b, _c, _d, _e;
super({
identityMetadata: strategyOptions.store.identityMetadata,
clientID: strategyOptions.store.clientID,
clientSecret: strategyOptions.store.clientSecret,
responseType: (_a = strategyOptions.store.responseType) !== null && _a !== void 0 ? _a : types_1.ResponseType.Code,
responseMode: (_b = strategyOptions.store.responseMode) !== null && _b !== void 0 ? _b : types_1.ResponseMode.Query,
redirectUrl: strategyOptions.store.callbackUrl,
allowHttpForRedirectUrl: (_c = strategyOptions.store.allowHttpForRedirectUrl) !== null && _c !== void 0 ? _c : false,
validateIssuer: (_d = strategyOptions.store.validateIssuer) !== null && _d !== void 0 ? _d : true,
isB2C: (_e = strategyOptions.store.isB2C) !== null && _e !== void 0 ? _e : false,
issuer: strategyOptions.store.issuer,
passReqToCallback: true,
scope: strategyOptions.store.scope,
});
this.container = container;
this.configModule = configModule;
this.strategyOptions = strategyOptions;
this.strict = strict;
}
async validate(req, profile) {
var _a, _b;
if (this.strategyOptions.store.verifyCallback) {
return await this.strategyOptions.store.verifyCallback(this.container, req, profile, this.strict);
}
const authprofile = {
emails: [{ value: profile === null || profile === void 0 ? void 0 : profile.upn }],
name: { givenName: (_a = profile === null || profile === void 0 ? void 0 : profile.name) === null || _a === void 0 ? void 0 : _a.givenName, familyName: (_b = profile === null || profile === void 0 ? void 0 : profile.name) === null || _b === void 0 ? void 0 : _b.familyName },
};
return await (0, validate_callback_1.validateStoreCallback)(authprofile, {
container: this.container,
strategyErrorIdentifier: 'azure_oidc',
strategyName,
strict: this.strict,
});
}
};
}
/**
* Return the router that hold the azure store authentication routes
* @param id
* @param azure
* @param configModule
*/
function getAzureStoreAuthRouter(id, azure, configModule) {
var _a, _b, _c;
const strategyName = `${types_1.AZURE_STORE_STRATEGY_NAME}_${id}`;
return (0, auth_routes_builder_1.passportAuthRoutesBuilder)({
domain: 'store',
configModule,
authPath: (_a = azure.store.authPath) !== null && _a !== void 0 ? _a : '/store/auth/azure',
authCallbackPath: (_b = azure.store.authCallbackPath) !== null && _b !== void 0 ? _b : '/store/auth/azure/cb',
successRedirect: azure.store.successRedirect,
strategyName,
passportAuthenticateMiddlewareOptions: {
scope: (_c = azure.store.scope) !== null && _c !== void 0 ? _c : [],
},
passportCallbackAuthenticateMiddlewareOptions: {
failureRedirect: azure.store.failureRedirect,
},
expiresIn: azure.store.expiresIn,
});
}
//# sourceMappingURL=store.js.map