How to use the httpntlm.ntlm.createType1Message function in httpntlm

To help you get started, we’ve selected a few httpntlm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github postmanlabs / postman-runtime / test / fixtures / server.js View on Github external
options = options || {};

    var type2Message = 'NTLM ' +
            'TlRMTVNTUAACAAAAHgAeADgAAAAFgoqiBevywvJykjAAAAAAAAAAAJgAmABWAAAA' +
            'CgC6RwAAAA9EAEUAUwBLAFQATwBQAC0ASgBTADQAVQBKAFQARAACAB4ARABFAFMA' +
            'SwBUAE8AUAAtAEoAUwA0AFUASgBUAEQAAQAeAEQARQBTAEsAVABPAFAALQBKAFMA' +
            'NABVAEoAVABEAAQAHgBEAEUAUwBLAFQATwBQAC0ASgBTADQAVQBKAFQARAADAB4A' +
            'RABFAFMASwBUAE8AUAAtAEoAUwA0AFUASgBUAEQABwAIADmguzCHn9UBAAAAAA==',
        parsedType2Message = ntlmUtils.parseType2Message(type2Message, _.noop),

        username = options.username || 'username',
        password = options.password || 'password',
        domain = options.domain || '',
        workstation = options.workstation || '',

        type1Message = ntlmUtils.createType1Message({
            domain,
            workstation
        }),
        type3Message = ntlmUtils.createType3Message(parsedType2Message, {
            domain,
            workstation,
            username,
            password
        }),

        handler = function (req, res) {
            var authHeaders = req.headers.authorization;

            // send type2 message and ask for type3 message
            if (authHeaders && authHeaders.startsWith(type1Message.slice(0, 20))) {
                res.writeHead(401, {
github postmanlabs / postman-runtime / lib / authorizer / ntlm.js View on Github external
if (!domain) {
            parsedParameters = parseParametersFromUsername(username) || {};

            username = parsedParameters.username;
            domain = parsedParameters.domain;
        }

        if (state === STATES.INITIALIZED) {
            // Nothing to do if the server does not ask us for auth in the first place.
            if (!(response.headers.has(WWW_AUTHENTICATE, NTLM) ||
                  response.headers.has(WWW_AUTHENTICATE, NEGOTIATE))) {
                return done(null, true);
            }

            // Create a type 1 message to send to the server
            negotiateMessage = ntlmUtil.createType1Message({
                domain: domain,
                workstation: workstation
            });

            // Add the type 1 message as the auth header
            auth.set(NTLM_HEADER, negotiateMessage);

            // Update the state
            auth.set(STATE, STATES.T1_MSG_CREATED);

            // ask runtime to replay the request
            return done(null, false);
        }
        else if (state === STATES.T1_MSG_CREATED) {
            // At this point, we can assume that the type 1 message was sent to the server