UNPKG

oauth-entra-id

Version:

🛡️ A Secure, Performant, and Feature-Rich OAuth 2.0 Integration for Microsoft Entra ID — Fully Abstracted and Production-Ready.

95 lines (93 loc) 3.48 kB
import { $sharedHandleAuthentication, $sharedHandleCallback, $sharedHandleLogout, $sharedHandleOnBehalfOf, $sharedMiddleware } from './chunk-IJAH4JBE.js'; import { OAuthProvider, OAuthError } from './chunk-VN6QIMDR.js'; // src/exports/nestjs.ts var ERROR_MSG = "authConfig not initialized or incorrect usage of NestJS handlers"; var ERROR_DESC = "Ensure you have called `authConfig(config)` during app setup before endpoints, and are importing all functions from the NestJS-specific entry point."; var nestjsOAuthProvider = void 0; function authConfig(config) { return (req, _res, next) => { if (!nestjsOAuthProvider) { nestjsOAuthProvider = new OAuthProvider(config); } req.oauthProvider = nestjsOAuthProvider; req.serverType = "nestjs"; next(); }; } async function handleAuthentication(req, res) { try { if (!req.oauthProvider || req.serverType !== "nestjs") { throw new OAuthError({ msg: ERROR_MSG, desc: ERROR_DESC, status: 500 }); } await $sharedHandleAuthentication(req, res); } catch (err) { if (err instanceof OAuthError) throw err; throw new OAuthError({ msg: "Something went wrong...", desc: err instanceof Error ? err.message : typeof err === "string" ? err : String(err), status: 500 }); } } async function handleCallback(req, res) { try { if (!req.oauthProvider || req.serverType !== "nestjs") { throw new OAuthError({ msg: ERROR_MSG, desc: ERROR_DESC, status: 500 }); } await $sharedHandleCallback(req, res); } catch (err) { if (err instanceof OAuthError) throw err; if (err instanceof Error) throw new OAuthError({ msg: "internal", desc: err.message, status: 500 }); throw new OAuthError({ msg: "internal", desc: "Something went wrong", status: 500 }); } } async function handleLogout(req, res) { try { if (!req.oauthProvider || req.serverType !== "nestjs") { throw new OAuthError({ msg: ERROR_MSG, desc: ERROR_DESC, status: 500 }); } await $sharedHandleLogout(req, res); } catch (err) { if (err instanceof OAuthError) throw err; throw new OAuthError({ msg: "Something went wrong", desc: err instanceof Error ? err.message : String(err), status: 500 }); } } async function handleOnBehalfOf(req, res) { try { if (!req.oauthProvider || req.serverType !== "nestjs") { throw new OAuthError({ msg: ERROR_MSG, desc: ERROR_DESC, status: 500 }); } await $sharedHandleOnBehalfOf(req, res); } catch (err) { if (err instanceof OAuthError) throw err; throw new OAuthError({ msg: "Something went wrong", desc: err instanceof Error ? err.message : String(err), status: 500 }); } } async function isAuthenticated(req, res, cb) { try { if (!req.oauthProvider || req.serverType !== "nestjs") { throw new OAuthError({ msg: ERROR_MSG, desc: ERROR_DESC, status: 500 }); } const { userInfo, tryInjectData } = await $sharedMiddleware(req, res); if (cb) await cb({ userInfo, tryInjectData }); return true; } catch (err) { if (err instanceof OAuthError) throw err; throw new OAuthError({ msg: "Something went wrong", desc: err instanceof Error ? err.message : String(err), status: 500 }); } } export { authConfig, handleAuthentication, handleCallback, handleLogout, handleOnBehalfOf, isAuthenticated, nestjsOAuthProvider }; //# sourceMappingURL=nestjs.js.map //# sourceMappingURL=nestjs.js.map