lib/authorizer/digest.js
function (params) {
        var algorithm = params.algorithm,
            username = params.username,
            realm = params.realm,
            password = params.password,
            method = params.method,
            nonce = params.nonce,
            nonceCount = params.nonceCount,
            clientNonce = params.clientNonce,
            opaque = params.opaque,
            qop = params.qop,
            uri = params.uri,

            // RFC defined terms, http://tools.ietf.org/html/rfc2617#section-3
            A0,
            A1,
            A2,
            hashA1,
            hashA2,

            reqDigest,
            headerParams;

        if (algorithm === MD5_SESS) {
            A0 = crypto.MD5(username + COLON + realm + COLON + password).toString();
            A1 = A0 + COLON + nonce + COLON + clientNonce;
        }
        else {
            A1 = username + COLON + realm + COLON + password;
        }

        if (qop === AUTH_INT) {
            A2 = method + COLON + uri + COLON + crypto.MD5(params.body);
        }
        else {
            A2 = method + COLON + uri;
        }
        hashA1 = crypto.MD5(A1).toString();
        hashA2 = crypto.MD5(A2).toString();

        if (qop === AUTH || qop === AUTH_INT) {
            reqDigest = crypto.MD5([hashA1, nonce, nonceCount, clientNonce, qop, hashA2].join(COLON)).toString();
        }
        else {
            reqDigest = crypto.MD5([hashA1, nonce, hashA2].join(COLON)).toString();
        }

        headerParams = [USERNAME_EQUALS_QUOTE + username + QUOTE,
            REALM_EQUALS_QUOTE + realm + QUOTE,
            NONCE_EQUALS_QUOTE + nonce + QUOTE,
            URI_EQUALS_QUOTE + uri + QUOTE
        ];

        algorithm && headerParams.push(ALGORITHM_EQUALS_QUOTE + algorithm + QUOTE);

        if (qop === AUTH || qop === AUTH_INT) {
            headerParams.push(QOP_EQUALS + qop);
        }

        if (qop === AUTH || qop === AUTH_INT || algorithm === MD5_SESS) {
            nonceCount && headerParams.push(NC_EQUALS + nonceCount);
            headerParams.push(CNONCE_EQUALS_QUOTE + clientNonce + QUOTE);
        }

        headerParams.push(RESPONSE_EQUALS_QUOTE + reqDigest + QUOTE);
        opaque && headerParams.push(OPAQUE_EQUALS_QUOTE + opaque + QUOTE);

        return DIGEST_PREFIX + headerParams.join(', ');
    }
function (params) {
        var algorithm = params.algorithm,
            username = params.username,
            realm = params.realm,
            password = params.password,
            method = params.method,
            nonce = params.nonce,
            nonceCount = params.nonceCount,
            clientNonce = params.clientNonce,
            opaque = params.opaque,
            qop = params.qop,
            uri = params.uri,

            // RFC defined terms, http://tools.ietf.org/html/rfc2617#section-3
            A0,
            A1,
            A2,
            hashA1,
            hashA2,

            reqDigest,
            headerParams;

        if (algorithm === MD5_SESS) {
            A0 = crypto.MD5(username + COLON + realm + COLON + password).toString();
            A1 = A0 + COLON + nonce + COLON + clientNonce;
        }
        else {
            A1 = username + COLON + realm + COLON + password;
        }

        if (qop === AUTH_INT) {
            A2 = method + COLON + uri + COLON + crypto.MD5(params.body);
        }
        else {
            A2 = method + COLON + uri;
        }
        hashA1 = crypto.MD5(A1).toString();
        hashA2 = crypto.MD5(A2).toString();

        if (qop === AUTH || qop === AUTH_INT) {
            reqDigest = crypto.MD5([hashA1, nonce, nonceCount, clientNonce, qop, hashA2].join(COLON)).toString();
        }
        else {
            reqDigest = crypto.MD5([hashA1, nonce, hashA2].join(COLON)).toString();
        }

        headerParams = [USERNAME_EQUALS_QUOTE + username + QUOTE,
            REALM_EQUALS_QUOTE + realm + QUOTE,
            NONCE_EQUALS_QUOTE + nonce + QUOTE,
            URI_EQUALS_QUOTE + uri + QUOTE
        ];

        algorithm && headerParams.push(ALGORITHM_EQUALS_QUOTE + algorithm + QUOTE);

        if (qop === AUTH || qop === AUTH_INT) {
            headerParams.push(QOP_EQUALS + qop);
        }

        if (qop === AUTH || qop === AUTH_INT || algorithm === MD5_SESS) {
            nonceCount && headerParams.push(NC_EQUALS + nonceCount);
            headerParams.push(CNONCE_EQUALS_QUOTE + clientNonce + QUOTE);
        }

        headerParams.push(RESPONSE_EQUALS_QUOTE + reqDigest + QUOTE);
        opaque && headerParams.push(OPAQUE_EQUALS_QUOTE + opaque + QUOTE);

        return DIGEST_PREFIX + headerParams.join(', ');
    }
function ( params ) { var algorithm = params . algorithm , username = params . username , realm = params . realm , password = params . password , method = params . method , nonce = params . nonce , nonceCount = params . nonceCount , clientNonce = params . clientNonce , opaque = params . opaque , qop = params . qop , uri = params . uri , // RFC defined terms, http://tools.ietf.org/html/rfc2617#section-3 A0 , A1 , A2 , hashA1 , hashA2 , reqDigest , headerParams ; if ( algorithm === MD5_SESS ) { A0 = crypto . MD5 ( username + COLON + realm + COLON + password ) . toString ( ) ; A1 = A0 + COLON + nonce + COLON + clientNonce ; } else { A1 = username + COLON + realm + COLON + password ; } if ( qop === AUTH_INT ) { A2 = method + COLON + uri + COLON + crypto . MD5 ( params . body ) ; } else { A2 = method + COLON + uri ; } hashA1 = crypto . MD5 ( A1 ) . toString ( ) ; hashA2 = crypto . MD5 ( A2 ) . toString ( ) ; if ( qop === AUTH || qop === AUTH_INT ) { reqDigest = crypto . MD5 ( [ hashA1 , nonce , nonceCount , clientNonce , qop , hashA2 ] . join ( COLON ) ) . toString ( ) ; } else { reqDigest = crypto . MD5 ( [ hashA1 , nonce , hashA2 ] . join ( COLON ) ) . toString ( ) ; } headerParams = [ USERNAME_EQUALS_QUOTE + username + QUOTE , REALM_EQUALS_QUOTE + realm + QUOTE , NONCE_EQUALS_QUOTE + nonce + QUOTE , URI_EQUALS_QUOTE + uri + QUOTE ] ; algorithm && headerParams . push ( ALGORITHM_EQUALS_QUOTE + algorithm + QUOTE ) ; if ( qop === AUTH || qop === AUTH_INT ) { headerParams . push ( QOP_EQUALS + qop ) ; } if ( qop === AUTH || qop === AUTH_INT || algorithm === MD5_SESS ) { nonceCount && headerParams . push ( NC_EQUALS + nonceCount ) ; headerParams . push ( CNONCE_EQUALS_QUOTE + clientNonce + QUOTE ) ; } headerParams . push ( RESPONSE_EQUALS_QUOTE + reqDigest + QUOTE ) ; opaque && headerParams . push ( OPAQUE_EQUALS_QUOTE + opaque + QUOTE ) ; return DIGEST_PREFIX + headerParams . join ( ', ' ) ; }
Computes the Digest Authentication header from the given parameters.

@param {Object} params
@param {String} params.algorithm
@param {String} params.username
@param {String} params.realm
@param {String} params.password
@param {String} params.method
@param {String} params.nonce
@param {String} params.nonceCount
@param {String} params.clientNonce
@param {String} params.opaque
@param {String} params.qop
@param {String} params.uri
@returns {String}
Computes the Digest Authentication header from the given parameters .