import BASIC from './mechanisms/basic'; import DIGEST from './mechanisms/digest'; import BEARER from './mechanisms/bearer'; export declare type Mechanism = { type: string; parseWWWAuthenticateRest(rest: string): Record; buildWWWAuthenticateRest(data: Record): string; parseAuthorizationRest(rest: string): Record; buildAuthorizationRest(data: Record): string; }; /** * @module http-auth-utils */ /** * Natively supported authentication mechanisms. * @type {Array} */ declare const mechanisms: Mechanism[]; export { BASIC, DIGEST, BEARER, mechanisms }; /** * Parse HTTP WWW-Authenticate header contents. * @type {Function} * @param {string} header * The WWW-Authenticate header contents * @param {Array} [authMechanisms=[BASIC, DIGEST, BEARER]] * Allow providing custom authentication mechanisms. * @param {Object} [options] * Parsing options * @param {boolean} [options.strict=true] * Strictly detect the mechanism type (case sensitive) * @return {Object} Result of the contents parse. * @api public * @example * assert.deepEqual( * parseWWWAuthenticateHeader('Basic realm="test"'), { * type: 'Basic', * data: { * realm: 'test' * } * } * ); */ export declare function parseWWWAuthenticateHeader(header: string, authMechanisms?: T[], { strict }?: { strict: boolean; }): { type: T['type']; data: ReturnType; }; /** * Parse HTTP Authorization header contents. * @type {Function} * @param {string} header The Authorization header contents * @param {Array} [authMechanisms=[BASIC, DIGEST, BEARER]] * Allow custom authentication mechanisms. * @param {Object} [options] * Parsing options * @param {boolean} [options.strict=true] * Strictly detect the mechanism type (case sensitive) * @return {Object} Result of the contents parse. * @api public * @example * assert.deepEqual( * parseAuthorizationHeader('Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='), { * type: 'Basic', * data: { * hash: 'QWxhZGRpbjpvcGVuIHNlc2FtZQ==' * } * } * ); */ export declare function parseAuthorizationHeader(header: string, authMechanisms?: T[], { strict }?: { strict: boolean; }): { type: T['type']; data: ReturnType; }; /** * Build HTTP WWW-Authenticate header value. * @type {Function} * @param {Object} authMechanism The mechanism to use * @param {Object} * The WWW-Authenticate header contents to base the value on. * @return {string} The header value. * @api public * @example * assert.deepEqual( * buildWWWAuthenticateHeader(BASIC, { * realm: 'test' * }), * 'Basic realm="test"' * ); */ export declare function buildWWWAuthenticateHeader(authMechanism: T, data: Parameters[0]): string; /** * Build HTTP Authorization header value. * @type {Function} * @param {Object} authMechanism The mechanism to use * @param {Object} * The Authorization header contents to base the value on. * @return {string} The header value. * @api public * @example * assert.deepEqual( * buildAuthorizationHeader(BASIC, { * realm: 'test' * }), * 'Basic realm="test"' * ); */ export declare function buildAuthorizationHeader(authMechanism: T, data: Parameters[0]): string;