oauth-entra-id
Version:
🛡️ A Secure, Performant, and Feature-Rich OAuth 2.0 Integration for Microsoft Entra ID — Fully Abstracted and Production-Ready.
76 lines (73 loc) • 3.69 kB
TypeScript
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 expressOAuthProvider: OAuthProvider;
/**
* Factory that binds a singleton OAuthProvider to every Express 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, next: NextFunction) => Promise<void>;
/**
* Route handler that processes the OAuth callback after user authentication.
*
* ### Body:
* - `code` - The authorization code received from Microsoft.
* - `state` - The state parameter received from Microsoft, used to prevent CSRF attacks and store session state.
*
* @throws {OAuthError} if there is any issue.
*/
declare function handleCallback(): (req: Request, res: Response, next: NextFunction) => 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).
*
* @throws {OAuthError} if there is any issue.
*/
declare function handleLogout(): (req: Request, res: Response, next: NextFunction) => 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, next: NextFunction) => 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.
*
* @throws {OAuthError} if there is any issue with the configuration or authentication.
*/
declare function protectRoute(cb?: CallbackFunction): (req: Request, res: Response, next: NextFunction) => Promise<void>;
export { authConfig, expressOAuthProvider, handleAuthentication, handleCallback, handleLogout, handleOnBehalfOf, protectRoute };