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.1/lib/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict';\r\n\r\nconst Boom = require('boom');\r\nconst Hawk = require('hawk');\r\nconst Hoek = require('hoek');\r\n\r\n\r\nconst internals = {};\r\n\r\n\r\nexports.plugin = {\r\n    pkg: require('../package.json'),\r\n    requirements: {\r\n        hapi: '>=17.7.0'\r\n    },\r\n    register: function (server) {\r\n\r\n        server.auth.scheme('hawk', internals.hawk);\r\n        server.auth.scheme('bewit', internals.bewit);\r\n    }\r\n};\r\n\r\n\r\ninternals.hawk = function (server, options) {\r\n\r\n    Hoek.assert(options, 'Invalid hawk scheme options');\r\n    Hoek.assert(options.getCredentialsFunc, 'Missing required getCredentialsFunc method in hawk scheme configuration');\r\n\r\n    const settings = Hoek.clone(options);\r\n    settings.hawk = settings.hawk || {};\r\n\r\n    const scheme = {\r\n        authenticate: async function (request, h) {\r\n\r\n            try {\r\n                var result = await Hawk.server.authenticate(request.raw.req, settings.getCredentialsFunc, settings.hawk);\r\n            }\r\n            catch (err) {\r\n                const { credentials, artifacts } = err;\r\n                return h.unauthenticated(err, credentials ? { credentials, artifacts } : undefined);\r\n            }\r\n\r\n            if (request.route.settings.auth.payload) {\r\n                request.events.once('peek', (chunk) => {\r\n\r\n                    const payloadHash = Hawk.crypto.initializePayloadHash(request.auth.credentials.algorithm, request.headers['content-type']);\r\n                    payloadHash.update(chunk);\r\n\r\n                    request.events.on('peek', (chunk2) => payloadHash.update(chunk2));\r\n\r\n                    request.events.once('finish', () => {\r\n\r\n                        request.plugins['hapi-auth-hawk'] = { payloadHash: Hawk.crypto.finalizePayloadHash(payloadHash) };\r\n                    });\r\n                });\r\n            }\r\n\r\n            return h.authenticated(result);\r\n        },\r\n        payload: function (request, h) {\r\n\r\n            if (!request.auth.artifacts.hash) {\r\n                throw Boom.unauthorized(null, 'Hawk');      // Missing\r\n            }\r\n\r\n            const plugin = request.plugins['hapi-auth-hawk'];\r\n\r\n            if (!plugin) {\r\n                throw Boom.unauthorized('Payload is invalid');\r\n            }\r\n\r\n            try {\r\n                Hawk.server.authenticatePayloadHash(plugin.payloadHash, request.auth.artifacts);\r\n                return h.continue;\r\n            }\r\n            catch (err) {\r\n                throw Boom.unauthorized('Payload is invalid');\r\n            }\r\n        },\r\n        response: function (request, h) {\r\n\r\n            const response = request.response;\r\n            const payloadHash = Hawk.crypto.initializePayloadHash(request.auth.credentials.algorithm, response.headers['content-type']);\r\n\r\n            response.header('trailer', 'server-authorization');\r\n            response.header('transfer-encoding', 'chunked');\r\n\r\n            delete response.headers['content-length'];  // Cannot not send a content-length header alongside transfer-encoding (https://tools.ietf.org/html/rfc7230#section-3.3.3)\r\n\r\n            response.events.on('peek', (chunk) => {\r\n\r\n                payloadHash.update(chunk);\r\n            });\r\n\r\n            response.events.once('finish', () => {\r\n\r\n                const header = Hawk.server.header(request.auth.credentials, request.auth.artifacts, { hash: Hawk.crypto.finalizePayloadHash(payloadHash) });\r\n                request.raw.res.addTrailers({ 'server-authorization': header });\r\n            });\r\n\r\n            return h.continue;\r\n        }\r\n    };\r\n\r\n    return scheme;\r\n};\r\n\r\n\r\ninternals.bewit = function (server, options) {\r\n\r\n    Hoek.assert(options, 'Invalid bewit scheme options');\r\n    Hoek.assert(options.getCredentialsFunc, 'Missing required getCredentialsFunc method in bewit scheme configuration');\r\n\r\n    const settings = Hoek.clone(options);\r\n    settings.hawk = settings.hawk || {};\r\n\r\n    const scheme = {\r\n        authenticate: async function (request, h) {\r\n\r\n            try {\r\n                const { credentials, attributes } = await Hawk.server.authenticateBewit(request.raw.req, settings.getCredentialsFunc, settings.hawk);\r\n                return h.authenticated({ credentials, attributes });\r\n            }\r\n            catch (err) {\r\n                const { credentials, attributes } = err;\r\n                return h.unauthenticated(err, credentials ? { credentials, attributes } : undefined);\r\n            }\r\n        }\r\n    };\r\n\r\n    return scheme;\r\n};\r\n"]}