UNPKG

rpc_ts

Version:

Remote Procedure Calls in TypeScript made simple

50 lines (49 loc) 2.12 kB
/** * @module ModuleRpcContextServer * * Implements a JWT-based `AuthClaimsHandler` that extracts authentication * claims from JWT tokens. * * JWT tokens are defined in [RFC7519](https://tools.ietf.org/html/rfc7519). We * validate the claims against [RFC7523](https://tools.ietf.org/html/rfc7523), which defines * a profile for OAuth 2.0. We only deal with JSON Web Signatures, not with plain text. * * Abstract of RFC7519: * * JSON Web Token (JWT) is a compact, URL-safe means of representing * claims to be transferred between two parties. The claims in a JWT * are encoded as a JSON object that is used as the payload of a JSON * Web Signature (JWS) structure or as the plaintext of a JSON Web * Encryption (JWE) structure, enabling the claims to be digitally * signed or integrity protected with a Message Authentication Code * (MAC) and/or encrypted. * * @license * Copyright (c) Aiden.ai * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import { AuthClaimsHandler } from './token_auth_handler'; /** * The authentication claims are given in JWT as a string map. */ export interface EncodedJwtAuthClaims { [key: string]: string; } /** * Decodes raw JWT claims into a custom data type. */ export declare type JwtAuthClaimsDecoder<AuthClaims> = (encodedClaims: EncodedJwtAuthClaims) => Promise<AuthClaims>; /** * Gets an [[AuthClaimsHandler]] that extracts authentication claims from JWT tokens. * * @param jwksUrl The URL from which to retrieve the JSON-serialized Web Key Set (JWKS) * used to validate the JWT tokens. * @param expectedAudiences The audiences expected from the JWT tokens (the 'aud' * authentication claim must be included in this list). * @param decodeClaims Decode raw JWT claims into a custom data type. * * @throws `TokenValidationError` if the token is invalid. */ export declare function getJwtAuthClaimsHandler<AuthClaims>(jwksUrl: string, expectedAudiences: string[], decodeClaims: JwtAuthClaimsDecoder<AuthClaims>): AuthClaimsHandler<AuthClaims>;