UNPKG

oauth-entra-id

Version:

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

102 lines (99 loc) 3.93 kB
'use strict'; var chunkF55YGO6G_cjs = require('./chunk-F55YGO6G.cjs'); var chunk7MTPXR5V_cjs = require('./chunk-7MTPXR5V.cjs'); // 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."; exports.nestjsOAuthProvider = void 0; function authConfig(config) { return (req, _res, next) => { if (!exports.nestjsOAuthProvider) { exports.nestjsOAuthProvider = new chunk7MTPXR5V_cjs.OAuthProvider(config); } req.oauthProvider = exports.nestjsOAuthProvider; req.serverType = "nestjs"; next(); }; } async function handleAuthentication(req, res) { try { if (!req.oauthProvider || req.serverType !== "nestjs") { throw new chunk7MTPXR5V_cjs.OAuthError({ msg: ERROR_MSG, desc: ERROR_DESC, status: 500 }); } await chunkF55YGO6G_cjs.$sharedHandleAuthentication(req, res); } catch (err) { if (err instanceof chunk7MTPXR5V_cjs.OAuthError) throw err; throw new chunk7MTPXR5V_cjs.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 chunk7MTPXR5V_cjs.OAuthError({ msg: ERROR_MSG, desc: ERROR_DESC, status: 500 }); } await chunkF55YGO6G_cjs.$sharedHandleCallback(req, res); } catch (err) { if (err instanceof chunk7MTPXR5V_cjs.OAuthError) throw err; if (err instanceof Error) throw new chunk7MTPXR5V_cjs.OAuthError({ msg: "internal", desc: err.message, status: 500 }); throw new chunk7MTPXR5V_cjs.OAuthError({ msg: "internal", desc: "Something went wrong", status: 500 }); } } async function handleLogout(req, res) { try { if (!req.oauthProvider || req.serverType !== "nestjs") { throw new chunk7MTPXR5V_cjs.OAuthError({ msg: ERROR_MSG, desc: ERROR_DESC, status: 500 }); } await chunkF55YGO6G_cjs.$sharedHandleLogout(req, res); } catch (err) { if (err instanceof chunk7MTPXR5V_cjs.OAuthError) throw err; throw new chunk7MTPXR5V_cjs.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 chunk7MTPXR5V_cjs.OAuthError({ msg: ERROR_MSG, desc: ERROR_DESC, status: 500 }); } await chunkF55YGO6G_cjs.$sharedHandleOnBehalfOf(req, res); } catch (err) { if (err instanceof chunk7MTPXR5V_cjs.OAuthError) throw err; throw new chunk7MTPXR5V_cjs.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 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 }); return true; } catch (err) { if (err instanceof chunk7MTPXR5V_cjs.OAuthError) throw err; throw new chunk7MTPXR5V_cjs.OAuthError({ msg: "Something went wrong", desc: err instanceof Error ? err.message : String(err), status: 500 }); } } exports.authConfig = authConfig; exports.handleAuthentication = handleAuthentication; exports.handleCallback = handleCallback; exports.handleLogout = handleLogout; exports.handleOnBehalfOf = handleOnBehalfOf; exports.isAuthenticated = isAuthenticated; //# sourceMappingURL=nestjs.cjs.map //# sourceMappingURL=nestjs.cjs.map