/** * @module http-auth-utils/mechanisms/digest */ declare type DigestWWWAuthenticateData = { realm: string; domain?: string; nonce: string; opaque?: string; stale?: 'true' | 'false'; algorithm?: 'MD5' | 'MD5-sess' | 'token'; qop?: 'auth' | 'auth-int' | string; }; declare type DigestAuthorizationData = { username: string; realm: string; nonce: string; uri: string; response: string; algorithm?: string; cnonce?: string; opaque?: string; qop?: string; nc?: string; }; /** * Digest authentication mechanism. * @type {Object} * @see http://tools.ietf.org/html/rfc2617#section-3 * @see http://tools.ietf.org/html/rfc2069#section-2 */ declare const DIGEST: { /** * The Digest 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( * DIGEST.parseWWWAuthenticateRest( * 'realm="testrealm@host.com", ' + * 'qop="auth, auth-int", ' + * 'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", ' + * 'opaque="5ccc069c403ebaf9f0171e9517f40e41"' * ), { * realm: 'testrealm@host.com', * qop: 'auth, auth-int', * nonce: 'dcd98b7102dd2f0e8b11d0f600bfb0c093', * opaque: '5ccc069c403ebaf9f0171e9517f40e41' * } * ); * @api public */ parseWWWAuthenticateRest: (rest: string) => DigestWWWAuthenticateData; /** * 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( * DIGEST.buildWWWAuthenticateRest({ * realm: 'testrealm@host.com', * qop: 'auth, auth-int', * nonce: 'dcd98b7102dd2f0e8b11d0f600bfb0c093', * opaque: '5ccc069c403ebaf9f0171e9517f40e41' * }), * 'realm="testrealm@host.com", ' + * 'qop="auth, auth-int", ' + * 'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", ' + * 'opaque="5ccc069c403ebaf9f0171e9517f40e41"' * ); * @api public */ buildWWWAuthenticateRest: (data: DigestWWWAuthenticateData) => 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( * DIGEST.parseAuthorizationRest( * 'username="Mufasa",' + * 'realm="testrealm@host.com",' + * 'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093",' + * 'uri="/dir/index.html",' + * 'qop="auth",' + * 'nc="00000001",' + * 'cnonce="0a4f113b",' + * 'response="6629fae49393a05397450978507c4ef1",' + * 'opaque="5ccc069c403ebaf9f0171e9517f40e41"' * ), { * username: "Mufasa", * realm: 'testrealm@host.com', * nonce: "dcd98b7102dd2f0e8b11d0f600bfb0c093", * uri: "/dir/index.html", * qop: 'auth', * nc: '00000001', * cnonce: "0a4f113b", * response: "6629fae49393a05397450978507c4ef1", * opaque: "5ccc069c403ebaf9f0171e9517f40e41" * } * ); * @api public */ parseAuthorizationRest: (rest: string) => DigestAuthorizationData; /** * Build the Authorization header rest. * @param {Object} data The content from wich to build the rest. * @return {String} The rest built. * @example * assert.equal( * DIGEST.buildAuthorizationRest({ * username: "Mufasa", * realm: 'testrealm@host.com', * nonce: "dcd98b7102dd2f0e8b11d0f600bfb0c093", * uri: "/dir/index.html", * qop: 'auth', * nc: '00000001', * cnonce: "0a4f113b", * response: "6629fae49393a05397450978507c4ef1", * opaque: "5ccc069c403ebaf9f0171e9517f40e41" * }), * 'username="Mufasa", ' + * 'realm="testrealm@host.com", ' + * 'nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", ' + * 'uri="/dir/index.html", ' + * 'response="6629fae49393a05397450978507c4ef1", ' + * 'cnonce="0a4f113b", ' + * 'opaque="5ccc069c403ebaf9f0171e9517f40e41", ' + * 'qop="auth", ' + * 'nc="00000001"' * ); * @api public */ buildAuthorizationRest: (data: DigestAuthorizationData) => string; /** * Compute the Digest authentication hash from the given credentials. * @param {Object} data The credentials to encode and other encoding details. * @return {String} The hash representing the credentials. * @example * assert.equal( * DIGEST.computeHash({ * username: 'Mufasa', * realm: 'testrealm@host.com', * password: 'Circle Of Life', * method: 'GET', * uri: '/dir/index.html', * nonce: 'dcd98b7102dd2f0e8b11d0f600bfb0c093', * nc: '00000001', * cnonce: '0a4f113b', * qop: 'auth', * algorithm: 'md5' * }), * '6629fae49393a05397450978507c4ef1' * ); * @api public */ computeHash: (data: { ha1?: string; algorithm: string; method: string; uri: string; realm: string; username: string; password: string; nonce: string; nc: string; cnonce: string; qop: string; }) => string; }; export default DIGEST;