/** * @module http-auth-utils/mechanisms/basic */ declare type BasicWWWAuthenticateData = { realm: string; }; declare type BasicAuthorizationData = { username: string; password: string; }; /** * Basic authentication mechanism. * @type {Object} * @see http://tools.ietf.org/html/rfc2617#section-2 */ declare const BASIC: { /** * The Basic auth mechanism prefix. * @type {String} */ type: string; /** * Parse the WWW Authenticate header rest. * @param {String} rest The header rest (string after the authentication mechanism prefix). * @return {Object} Object representing the result of the parse operation. * @example * assert.deepEqual( * BASIC.parseWWWAuthenticateRest('realm="perlinpinpin"'), { * realm: 'perlinpinpin' * } * ); * @api public */ parseWWWAuthenticateRest: (rest: string) => BasicWWWAuthenticateData; /** * Build the WWW Authenticate header rest. * @param {Object} data The content from wich to build the rest. * @return {String} The built rest. * @example * assert.equal( * BASIC.buildWWWAuthenticateRest({ * realm: 'perlinpinpin' * }), * 'realm="perlinpinpin"' * ); * @api public */ buildWWWAuthenticateRest: (data: BasicWWWAuthenticateData) => string; /** * Parse the Authorization header rest. * @param {String} rest The header rest (string after the authentication mechanism prefix).) * @return {Object} Object representing the result of the parse operation {hash}. * @example * assert.deepEqual( * BASIC.parseAuthorizationRest('QWxpIEJhYmE6b3BlbiBzZXNhbWU='), { * hash: 'QWxpIEJhYmE6b3BlbiBzZXNhbWU=', * username: 'Ali Baba', * password: 'open sesame' * } * ); * @api public */ parseAuthorizationRest: (rest: string) => BasicAuthorizationData & { hash: string; }; /** * Build the Authorization header rest. * @param {Object} content The content from wich to build the rest. * @return {String} The rest built. * @example * assert.equal( * BASIC.buildAuthorizationRest({ * hash: 'QWxpIEJhYmE6b3BlbiBzZXNhbWU=' * }), * 'QWxpIEJhYmE6b3BlbiBzZXNhbWU=' * ); * @api public */ buildAuthorizationRest: ({ hash, username, password, }: ({ hash: string; } & Partial) | (BasicAuthorizationData & { hash?: string | undefined; })) => string; /** * Compute the Basic authentication hash from the given credentials. * @param {Object} credentials The credentials to encode {username, password}. * @return {String} The hash representing the credentials. * @example * assert.equal( * BASIC.computeHash({ * username: 'Ali Baba', * password: 'open sesame' * }), * 'QWxpIEJhYmE6b3BlbiBzZXNhbWU=' * ); * @api public */ computeHash: ({ username, password, }: BasicAuthorizationData) => string; /** * Decode the Basic hash and return the corresponding credentials. * @param {String} hash The hash. * @return {Object} Object representing the credentials {username, password}. * @example * assert.deepEqual( * BASIC.decodeHash('QWxpIEJhYmE6b3BlbiBzZXNhbWU='), { * username: 'Ali Baba', * password: 'open sesame' * } * ); * @api public */ decodeHash: (hash: string) => BasicAuthorizationData; }; export default BASIC;