/// import { JsonWebKey } from 'crypto'; import { Storage } from './use-cases'; import { MakeHandleAuthentication, MakeHandleIsAuthorized } from './handlers/authorization'; export interface OAuth2ServerMiddlewareOptions { /** * Authenticates the resource owner. * * ```ts * import { OAuth2ServerMiddlewareOptions, Unauthenticated } from 'oauth2-server-nodejs'; * * const authenticate: OAuth2ServerMiddlewareOptions['authenticate'] = (req, res) => (client, authorizationRequest) => { * const subject = ''; * * if (!subject) { * // The resource owner is not authenticated. * throw new Unauthenticated(client, authorizationRequest); * } * * // Locally unique and never reassigned identifier within the issuer for the resource owner. * return Promise.resolve(subject); * }; * ``` */ authenticate: MakeHandleAuthentication; /** * Establishes whether the resource owner grants or denies the client's access request. * * ```ts * import { OAuth2ServerMiddlewareOptions, UnresolvedAuthorization } from 'oauth2-server-nodejs'; * * const authorize: OAuth2ServerMiddlewareOptions['authorize'] = (req, res) => (client, authorizationRequest) => { * const isAuthorized = false; * * if (isAuthorized === null) { * // The authorization server can't establish whether the resource owner grants or denies the client's access request. * throw new UnresolvedAuthorization(client, authorizationRequest); * } * * // Information whether the resource owner grants or denies the client's access request. * return Promise.resolve(isAuthorized); * }; * ``` */ authorize: MakeHandleIsAuthorized; storage: Storage; /** * Authorization server's issuer identifier URL. */ issuer: string; /** * JSON Web Key [RFC7517](https://datatracker.ietf.org/doc/html/rfc7517) document representing the authorization server's private key. */ jwk: JsonWebKey; /** * JSON array containing a list of the OAuth 2.0 "scope" values that this authorization server supports. */ scopes?: string[]; } export declare const oAuth2ServerMiddleware: ({ authenticate, authorize, storage, issuer, jwk, scopes, }: OAuth2ServerMiddlewareOptions) => import("express-serve-static-core").Router; export * from './adapters'; export { Unauthenticated, UnresolvedAuthorization } from './use-cases/authorization';