oauth-entra-id
Version:
🛡️ A Secure, Performant, and Feature-Rich OAuth 2.0 Integration for Microsoft Entra ID — Fully Abstracted and Production-Ready.
90 lines (87 loc) • 2.97 kB
JavaScript
;
var chunkF55YGO6G_cjs = require('./chunk-F55YGO6G.cjs');
var chunk7MTPXR5V_cjs = require('./chunk-7MTPXR5V.cjs');
// src/exports/express.ts
var ERROR_MSG = "authConfig not initialized or incorrect usage of Express handlers";
var ERROR_DESC = "Ensure you have called `authConfig(config)` during app setup before endpoints, and are importing all functions from the Express-specific entry point.";
exports.expressOAuthProvider = void 0;
function authConfig(config) {
return (req, _res, next) => {
if (!exports.expressOAuthProvider) {
exports.expressOAuthProvider = new chunk7MTPXR5V_cjs.OAuthProvider(config);
}
req.oauthProvider = exports.expressOAuthProvider;
req.serverType = "express";
next();
};
}
function handleAuthentication() {
return async (req, res, next) => {
try {
if (!req.oauthProvider || req.serverType !== "express") {
throw new chunk7MTPXR5V_cjs.OAuthError({ msg: ERROR_MSG, desc: ERROR_DESC, status: 500 });
}
await chunkF55YGO6G_cjs.$sharedHandleAuthentication(req, res);
} catch (err) {
next(err);
}
};
}
function handleCallback() {
return async (req, res, next) => {
try {
if (!req.oauthProvider || req.serverType !== "express") {
throw new chunk7MTPXR5V_cjs.OAuthError({ msg: ERROR_MSG, desc: ERROR_DESC, status: 500 });
}
await chunkF55YGO6G_cjs.$sharedHandleCallback(req, res);
} catch (err) {
next(err);
}
};
}
function handleLogout() {
return async (req, res, next) => {
try {
if (!req.oauthProvider || req.serverType !== "express") {
throw new chunk7MTPXR5V_cjs.OAuthError({ msg: ERROR_MSG, desc: ERROR_DESC, status: 500 });
}
await chunkF55YGO6G_cjs.$sharedHandleLogout(req, res);
} catch (err) {
next(err);
}
};
}
function handleOnBehalfOf() {
return async (req, res, next) => {
try {
if (!req.oauthProvider || req.serverType !== "express") {
throw new chunk7MTPXR5V_cjs.OAuthError({ msg: ERROR_MSG, desc: ERROR_DESC, status: 500 });
}
await chunkF55YGO6G_cjs.$sharedHandleOnBehalfOf(req, res);
} catch (err) {
next(err);
}
};
}
function protectRoute(cb) {
return async (req, res, next) => {
try {
if (!req.oauthProvider || req.serverType !== "express") {
throw new chunk7MTPXR5V_cjs.OAuthError({ msg: ERROR_MSG, desc: ERROR_DESC, status: 500 });
}
const { userInfo, tryInjectData } = await chunkF55YGO6G_cjs.$sharedMiddleware(req, res);
if (cb) await cb({ userInfo, tryInjectData });
next();
} catch (err) {
next(err);
}
};
}
exports.authConfig = authConfig;
exports.handleAuthentication = handleAuthentication;
exports.handleCallback = handleCallback;
exports.handleLogout = handleLogout;
exports.handleOnBehalfOf = handleOnBehalfOf;
exports.protectRoute = protectRoute;
//# sourceMappingURL=express.cjs.map
//# sourceMappingURL=express.cjs.map