lib/plugins/authorization.js
function authorizationParser(options) {

    function parseAuthorization(req, res, next) {
        req.authorization = {};
        req.username = 'anonymous';

        if (!req.headers.authorization) {
            return (next());
        }

        var pieces = req.headers.authorization.split(' ', 2);

        if (!pieces || pieces.length !== 2) {
            var e = new InvalidHeaderError('BasicAuth content ' +
                'is invalid.');
            return (next(e));
        }

        req.authorization.scheme = pieces[0];
        req.authorization.credentials = pieces[1];

        try {
            switch (pieces[0].toLowerCase()) {
                case 'basic':
                    req.authorization.basic = parseBasic(pieces[1]);
                    req.username = req.authorization.basic.username;
                    break;

                case 'signature':
                    req.authorization.signature =
                        parseSignature(req, options);
                    req.username =
                        req.authorization.signature.keyId;
                    break;

                default:
                    break;
            }
        } catch (e2) {
            return (next(e2));
        }

        return (next());
    }

    return (parseAuthorization);
}
function authorizationParser(options) {

    function parseAuthorization(req, res, next) {
        req.authorization = {};
        req.username = 'anonymous';

        if (!req.headers.authorization) {
            return (next());
        }

        var pieces = req.headers.authorization.split(' ', 2);

        if (!pieces || pieces.length !== 2) {
            var e = new InvalidHeaderError('BasicAuth content ' +
                'is invalid.');
            return (next(e));
        }

        req.authorization.scheme = pieces[0];
        req.authorization.credentials = pieces[1];

        try {
            switch (pieces[0].toLowerCase()) {
                case 'basic':
                    req.authorization.basic = parseBasic(pieces[1]);
                    req.username = req.authorization.basic.username;
                    break;

                case 'signature':
                    req.authorization.signature =
                        parseSignature(req, options);
                    req.username =
                        req.authorization.signature.keyId;
                    break;

                default:
                    break;
            }
        } catch (e2) {
            return (next(e2));
        }

        return (next());
    }

    return (parseAuthorization);
}
function authorizationParser ( options ) { function parseAuthorization ( req , res , next ) { req . authorization = { } ; req . username = 'anonymous' ; if ( ! req . headers . authorization ) { return ( next ( ) ) ; } var pieces = req . headers . authorization . split ( ' ' , 2 ) ; if ( ! pieces || pieces . length !== 2 ) { var e = new InvalidHeaderError ( 'BasicAuth content ' + 'is invalid.' ) ; return ( next ( e ) ) ; } req . authorization . scheme = pieces [ 0 ] ; req . authorization . credentials = pieces [ 1 ] ; try { switch ( pieces [ 0 ] . toLowerCase ( ) ) { case 'basic' : req . authorization . basic = parseBasic ( pieces [ 1 ] ) ; req . username = req . authorization . basic . username ; break ; case 'signature' : req . authorization . signature = parseSignature ( req , options ) ; req . username = req . authorization . signature . keyId ; break ; default : break ; } } catch ( e2 ) { return ( next ( e2 ) ) ; } return ( next ( ) ) ; } return ( parseAuthorization ) ; }
Returns a plugin that will parse the client's Authorization header.

Subsequent handlers will see `req.authorization`, which looks like:

{
scheme: <Basic|Signature|...>,
credentials: <Undecoded value of header>,
basic: {
username: $user
password: $password
}
}

`req.username` will also be set, and defaults to 'anonymous'.

@public
@function authorizationParser
@throws   {InvalidArgumentError}
@param    {Object} options an options object
@returns  {Function}
Returns a plugin that will parse the client s Authorization header .