UNPKG

@interopio/gateway

Version:

[![npm version](https://img.shields.io/npm/v/@interopio/gateway.svg)](https://www.npmjs.com/package/@interopio/gateway)

73 lines (65 loc) 2.7 kB
/** * Authentication Type that specifies the method of authentication and the type of the provided credentials. */ export type AuthenticationMethod = 'secret' // used for username/password authentication | 'access-token' // used for access tokens, e.g. OAuth2 | 'gateway-token' // internal use only, tokens issued by gateway peers | 'gateway-client' // internal use only, client based ; export type Authentication = { method?: AuthenticationMethod | string // present when method is 'secret' login?: string, // username used for authentication secret?: string, // password used for authentication // present when method is 'access-token' or 'gateway-token' token?: string // additional context for the authentication request, e.g. for custom authenticators providerContext?: unknown }; /** * Represents an authentication request. * It includes the authentication method and the credentials provided by the user. * The request may also include a requestId for challege and/or tracking. */ export type AuthenticationRequest = { authentication: Authentication requestId?: string, [key: string]: unknown }; /** * Represents a successful authentication response. * This indicates that the authentication process was successful. */ export type AuthenticationSuccess = { type: 'success', user?: string, [key: string]: unknown }; /** * Represents a challenge response in the authentication process. * This indicates that the authentication process requires further interaction. */ export type AuthenticationChallenge = { type: 'continue', authentication?: Authentication, [key: string]: unknown }; export type AuthenticationFailure = Error & {data?: unknown}; /** * Represents the response type for an authentication request. * It can either be a Success or a Challenge. */ export type AuthenticationResponse = AuthenticationSuccess | AuthenticationChallenge; /** * Authenticator function type that takes an AuthenticationRequest and returns a Promise of AuthenticationResponse. * The AuthenticationResponse may be either an AuthenticationSuccess or an AuthenticationChallenge. * * Successful authentication means the provided credentials are valid and the user is authenticated. * AuthenticationSuccess should contain the authenticated user's identifier. * * If a AuthenticationChallenge is returned, it indicates that the authentication process requires further interaction. * * If the authentication fails, the returned Promise should be rejected with an AuthenticationFailure. */ export type Authenticator = (authentication: AuthenticationRequest) => Promise<AuthenticationResponse>;