UNPKG

oauth-entra-id

Version:

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

75 lines (72 loc) 3.57 kB
import { d as OAuthProvider, c as OAuthConfig, C as CallbackFunction } from './types-jPLS3OFl.js'; import { Request, Response, NextFunction } from 'express'; import '@azure/msal-node'; import 'jsonwebtoken'; declare let nestjsOAuthProvider: OAuthProvider; /** * Factory that binds a singleton OAuthProvider to every NestJS request. * * @param config OAuthConfig for your Microsoft Entra ID app. */ declare function authConfig(config: OAuthConfig): (req: Request, _res: Response, next: NextFunction) => void; /** * Route handler that begins the OAuth flow by sending back authentication PKCE-based URL. * * ### Body: * - `loginPrompt` (optional) - Overrides the default login prompt behavior, can be `email`, `select_account`, or `sso`. * - `email` (optional) - Pre-fills the email field in the login form. * - `frontendUrl` (optional) - Redirects to this URL after successful login. * - `azureId` (optional) - Azure configuration ID to use, relevant if multiple Azure configurations (Defaults to the first one). * * @throws {OAuthError} if there is any issue. */ declare function handleAuthentication(req: Request, res: Response): Promise<void>; /** * Route handler that processes the OAuth callback after user authentication. * * ### Body: * - `code` (required) - The authorization code received from the OAuth provider. * - `state` (required) - The state parameter to validate the request. * * @throws {OAuthError} if there is any issue. */ declare function handleCallback(req: Request, res: Response): Promise<void>; /** * Route handler that clears session cookies and returns the Azure logout URL. * * ### Body: * - `frontendUrl` (optional) - Overrides the default redirect URL after logout. * - `azureId` (optional) - Azure configuration ID to use, relevant if multiple Azure configurations (Defaults to the first one). */ declare function handleLogout(req: Request, res: Response): Promise<void>; /** * Route handler that processes on-behalf-of requests to obtain an access token for a service principal. * * ### Body: * - `services` - An array of service names for which the access token is requested. * - `azureId` (optional) - Azure configuration ID to use, relevant if multiple Azure configurations (Defaults to the first one). * * @throws {OAuthError} if there is any issue. */ declare function handleOnBehalfOf(req: Request, res: Response): Promise<void>; /** * Middleware that protects a route by ensuring the user is authenticated. * * ### What it does: * - If `acceptB2BRequests` is enabled: * - Checks for a Bearer token in the Authorization header. * - Verifies the token and attaches user info to the request. * - If not: * - Validate the users access token cookie. * - If valid, attaches user info to the request. * - If invalid, it looks for a refresh token cookie and attempts to refresh the session. * - If the refresh is successful, it sets new cookies and attaches user info to the request. * - If the refresh fails, it throws an error. * * @param cb (optional) - A callback function that gives access to user info and an inject data function. Fires after the user is authenticated. * @returns True if the user is authenticated, otherwise throws an error. * * @throws {OAuthError} if there is any issue with the configuration or authentication. */ declare function isAuthenticated(req: Request, res: Response, cb?: CallbackFunction): Promise<boolean>; export { authConfig, handleAuthentication, handleCallback, handleLogout, handleOnBehalfOf, isAuthenticated, nestjsOAuthProvider };