{"_id":"@aredridel/hapi-auth-cookie","_rev":"5-05cd08db0ac3908f8dbfe6526f1ccc9b","name":"@aredridel/hapi-auth-cookie","description":"Cookie authentication plugin","dist-tags":{"latest":"2.2.0-full-redirect-1"},"versions":{"3.1.0-full-redirect-1":{"name":"@aredridel/hapi-auth-cookie","description":"Cookie authentication plugin","version":"3.1.0-full-redirect-1","repository":{"type":"git","url":"git://github.com/hapijs/hapi-auth-cookie.git"},"main":"lib/index.js","keywords":["hapi","plugin","auth","cookie","session"],"engines":{"node":">=0.10.32"},"dependencies":{"boom":"2.x.x","hoek":"2.x.x","joi":"6.x.x"},"peerDependencies":{"hapi":">=8.x.x"},"devDependencies":{"code":"1.x.x","hapi":"9.x.x","lab":"5.x.x"},"scripts":{"test":"lab -a code -t 100 -L","test-cov-html":"lab -a code -r html -o coverage.html"},"license":"BSD-3-Clause","gitHead":"0e19393dcf8dec82a75f346254fe213b011ea29d","bugs":{"url":"https://github.com/hapijs/hapi-auth-cookie/issues"},"homepage":"https://github.com/hapijs/hapi-auth-cookie#readme","_id":"@aredridel/hapi-auth-cookie@3.1.0-full-redirect-1","_shasum":"6ed1760d9da87d3df5d737616b1f92da273759dd","_from":".","_npmVersion":"3.3.2","_nodeVersion":"3.3.0","_npmUser":{"name":"aredridel","email":"aredridel@dinhe.net"},"dist":{"shasum":"6ed1760d9da87d3df5d737616b1f92da273759dd","tarball":"https://registry.npmjs.org/@aredridel/hapi-auth-cookie/-/hapi-auth-cookie-3.1.0-full-redirect-1.tgz","integrity":"sha512-DqPErQ8QOu9zwP1kwlFBa8c9IHV3p6ui4NIy7blwqfMsY6sfj33xnDrlq2rYOuKkBugz+mm9SiJCOtLazyecEw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGS8baEw4U0YdweKHm4sAQXMqJ2bj9VSkV/RMjazwtw7AiBB+mkDpCEZ7812DzKT7TDLM4o+2ANKETPxhZnQJbLIyw=="}]},"maintainers":[{"name":"aredridel","email":"aredridel@dinhe.net"}]},"2.1.0-full-redirect-1":{"name":"@aredridel/hapi-auth-cookie","description":"Cookie authentication plugin","version":"2.1.0-full-redirect-1","repository":{"type":"git","url":"git://github.com/hapijs/hapi-auth-cookie.git"},"main":"index","keywords":["hapi","plugin","auth","cookie","session"],"engines":{"node":">=0.10.32"},"dependencies":{"boom":"2.x.x","hoek":"2.x.x","joi":"6.x.x"},"peerDependencies":{"hapi":">=8.x.x"},"devDependencies":{"code":"1.x.x","hapi":"8.x.x","lab":"5.x.x"},"scripts":{"test":"make test-cov"},"licenses":[{"type":"BSD","url":"http://github.com/hapijs/hapi-auth-cookie/raw/master/LICENSE"}],"gitHead":"417e7c9e76bf5eaf53b7507aa12388ef93e8da48","bugs":{"url":"https://github.com/hapijs/hapi-auth-cookie/issues"},"homepage":"https://github.com/hapijs/hapi-auth-cookie#readme","_id":"@aredridel/hapi-auth-cookie@2.1.0-full-redirect-1","_shasum":"8f7fbeb2e52c870d307a7850852c6bc2b2ca5f38","_from":".","_npmVersion":"3.3.2","_nodeVersion":"3.3.0","_npmUser":{"name":"aredridel","email":"aredridel@dinhe.net"},"dist":{"shasum":"8f7fbeb2e52c870d307a7850852c6bc2b2ca5f38","tarball":"https://registry.npmjs.org/@aredridel/hapi-auth-cookie/-/hapi-auth-cookie-2.1.0-full-redirect-1.tgz","integrity":"sha512-bbIrEHJ4CzcxUKAIoRNVpulYRsPBrOWHg66ii+NzQgjOI2j1jjZCRagG/CZRCOvxnupFrTgo2peTPnkrpxUaNA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDqB/eV5Q2O7eA98tDjUUvRm09t36I4Sr4eG7xA2yeHoAiAikeBhr3jhaDAdxCdXjY6a4/9RZaPoJB72hWd0oziBjg=="}]},"maintainers":[{"name":"aredridel","email":"aredridel@dinhe.net"}]},"2.2.0-full-redirect-1":{"name":"@aredridel/hapi-auth-cookie","description":"Cookie authentication plugin","version":"2.2.0-full-redirect-1","repository":{"type":"git","url":"git://github.com/hapijs/hapi-auth-cookie.git"},"main":"index","keywords":["hapi","plugin","auth","cookie","session"],"engines":{"node":">=0.10.32"},"dependencies":{"boom":"2.x.x","hoek":"2.x.x","joi":"6.x.x"},"peerDependencies":{"hapi":">=8.x.x"},"devDependencies":{"code":"1.x.x","hapi":"8.x.x","lab":"5.x.x"},"scripts":{"test":"make test-cov"},"licenses":[{"type":"BSD","url":"http://github.com/hapijs/hapi-auth-cookie/raw/master/LICENSE"}],"gitHead":"af8c94c4e9297c9a28a81fd1d1d3d72cabdd5603","bugs":{"url":"https://github.com/hapijs/hapi-auth-cookie/issues"},"homepage":"https://github.com/hapijs/hapi-auth-cookie#readme","_id":"@aredridel/hapi-auth-cookie@2.2.0-full-redirect-1","_shasum":"d872f92cd88c6cc50ee3a3b125e14aaa4881f531","_from":".","_npmVersion":"3.3.2","_nodeVersion":"3.3.0","_npmUser":{"name":"aredridel","email":"aredridel@dinhe.net"},"dist":{"shasum":"d872f92cd88c6cc50ee3a3b125e14aaa4881f531","tarball":"https://registry.npmjs.org/@aredridel/hapi-auth-cookie/-/hapi-auth-cookie-2.2.0-full-redirect-1.tgz","integrity":"sha512-HyNOtNAXSumUGFFQDQ60zSH+0GnG12p0PQTABiQwrNpykS2i55qNO13iqtIwgXFiPCfRtesiL1k+cWtDD0mWow==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICvtp1/JSGctxAqtkfPSqqxrGSJFwhU+taNTnAN5NF57AiA9uAeOhprifk4utYHCUuLtu3ZI/KTxvpq8/l+pyStC3Q=="}]},"maintainers":[{"name":"aredridel","email":"aredridel@dinhe.net"}]}},"readme":"### hapi-auth-cookie\n\n[**hapi**](https://github.com/hapijs/hapi) Cookie authentication plugin\n\n[![Build Status](https://secure.travis-ci.org/hapijs/hapi-auth-cookie.png)](http://travis-ci.org/hapijs/hapi-auth-cookie)\n\nLead Maintainer: [James Weston](https://github.com/jaw187)\n\nCookie authentication provides a simple cookie-based session management. The user has to be\nauthenticated via other means, typically a web form, and upon successful authentication,\nreceive a reply with a session cookie. Subsequent requests containing the session cookie are\nauthenticated (the cookie uses [Iron](https://github.com/hueniverse/iron) to encrypt and sign the\nsession content) and validated via the provided `validateFunc` in case the cookie's encrypted\ncontent requires validation on each request. Note that cookie operates as a bearer token and anyone\nin possession of the cookie content can use it to impersonate its true owner. The `'cookie`' scheme\ntakes the following required options:\n\n- `cookie` - the cookie name. Defaults to `'sid'`.\n- `password` - used for Iron cookie encoding.\n- `ttl` - sets the cookie expires time in milliseconds. Defaults to single browser session (ends\n  when browser closes).\n- `domain` - sets the cookie Domain value. Defaults to none.\n- `path` - sets the cookie path value. Defaults to `/`.\n- `clearInvalid` - if `true`, any authentication cookie that fails validation will be marked as\n  expired in the response and cleared. Defaults to `false`.\n- `keepAlive` - if `true`, automatically sets the session cookie after validation to extend the\n  current session for a new `ttl` duration. Defaults to `false`.\n- `isSecure` - if `false`, the cookie is allowed to be transmitted over insecure connections which\n  exposes it to attacks. Defaults to `true`.\n- `isHttpOnly` - if `false`, the cookie will not include the 'HttpOnly' flag. Defaults to `true`.\n- `redirectTo` - optional login URI to redirect unauthenticated requests to. Note that using\n  `redirectTo` with authentication mode `'try'` will cause the protected endpoint to always\n  redirect, voiding `'try'` mode. To set an individual route to use or disable redirections, use\n  the route `plugins` config (`{ config: { plugins: { 'hapi-auth-cookie': { redirectTo: false } } } }`).\n  Defaults to no redirection.\n- `appendNext` - if `true` and `redirectTo` is `true`, appends the current request path to the\n  query component of the `redirectTo` URI using the parameter name `'next'`. Set to a string to use\n  a different parameter name. Defaults to `false`.\n- `redirectOnTry` - if `false` and route authentication mode is `'try'`, authentication errors will\n  not trigger a redirection. Requires **hapi** version 6.2.0 or newer. Defaults to `true`;\n- `validateFunc` - an optional session validation function used to validate the content of the\n  session cookie on each request. Used to verify that the internal session state is still valid\n  (e.g. user account still exists). The function has the signature `function(session, callback)`\n  where:\n    - `session` - is the session object set via `request.auth.session.set()`.\n    - `callback` - a callback function with the signature `function(err, isValid, credentials)`\n      where:\n        - `err` - an internal error.\n        - `isValid` - `true` if the content of the session is valid, otherwise `false`.\n        - `credentials` - a credentials object passed back to the application in\n          `request.auth.credentials`. If value is `null` or `undefined`, defaults to `session`. If\n          set, will override the current cookie as if `request.auth.session.set()` was called.\n\nWhen the cookie scheme is enabled on a route, the `request.auth.session` objects is decorated with\nthe following methods:\n- `set(session)` - sets the current session. Must be called after a successful login to begin the\n  session. `session` must be a non-null object, which is set on successful subsequent\n  authentications in `request.auth.credentials` where:\n    - `session` - the session object.\n- `set(key, value)` - sets a specific object key on the current session (which must already exist)\n  where:\n    - `key` - session key string.\n    - `value` - value to assign key.\n- `clear([key])` - clears the current session or session key where:\n    - `key` - optional key string to remove a specific property of the session. If none provided,\n      defaults to removing the entire session which is used to log the user out.\n- `ttl(msecs)` - sets the ttl of the current active session where:\n    - `msecs` - the new ttl in milliseconds.\n\nBecause this scheme decorates the `request` object with session-specific methods, it cannot be\nregistered more than once.\n\n```javascript\nvar Hapi = require('hapi');\n\nvar users = {\n    john: {\n        id: 'john',\n        password: 'password',\n        name: 'John Doe'\n    }\n};\n\nvar home = function (request, reply) {\n\n    reply('<html><head><title>Login page</title></head><body><h3>Welcome '\n      + request.auth.credentials.name\n      + '!</h3><br/><form method=\"get\" action=\"/logout\">'\n      + '<input type=\"submit\" value=\"Logout\">'\n      + '</form></body></html>');\n};\n\nvar login = function (request, reply) {\n\n    if (request.auth.isAuthenticated) {\n        return reply.redirect('/');\n    }\n\n    var message = '';\n    var account = null;\n\n    if (request.method === 'post') {\n\n        if (!request.payload.username ||\n            !request.payload.password) {\n\n            message = 'Missing username or password';\n        }\n        else {\n            account = users[request.payload.username];\n            if (!account ||\n                account.password !== request.payload.password) {\n\n                message = 'Invalid username or password';\n            }\n        }\n    }\n\n    if (request.method === 'get' ||\n        message) {\n\n        return reply('<html><head><title>Login page</title></head><body>'\n            + (message ? '<h3>' + message + '</h3><br/>' : '')\n            + '<form method=\"post\" action=\"/login\">'\n            + 'Username: <input type=\"text\" name=\"username\"><br>'\n            + 'Password: <input type=\"password\" name=\"password\"><br/>'\n            + '<input type=\"submit\" value=\"Login\"></form></body></html>');\n    }\n\n    request.auth.session.set(account);\n    return reply.redirect('/');\n};\n\nvar logout = function (request, reply) {\n\n    request.auth.session.clear();\n    return reply.redirect('/');\n};\n\nvar server = new Hapi.Server();\nserver.connection({ port: 8000 });\n\nserver.register(require('hapi-auth-cookie'), function (err) {\n\n    server.auth.strategy('session', 'cookie', {\n        password: 'secret',\n        cookie: 'sid-example',\n        redirectTo: '/login',\n        isSecure: false\n    });\n});\n\nserver.route([\n    {\n        method: 'GET',\n        path: '/',\n        config: {\n            handler: home,\n            auth: 'session'\n        }\n    },\n    {\n        method: ['GET', 'POST'],\n        path: '/login',\n        config: {\n            handler: login,\n            auth: {\n                mode: 'try',\n                strategy: 'session'\n            },\n            plugins: {\n                'hapi-auth-cookie': {\n                    redirectTo: false\n                }\n            }\n        }\n    },\n    {\n        method: 'GET',\n        path: '/logout',\n        config: {\n            handler: logout,\n            auth: 'session'\n        }\n    }\n]);\n\nserver.start();\n```\n\n","maintainers":[{"name":"aredridel","email":"aredridel@dinhe.net"}],"time":{"modified":"2022-06-12T14:47:26.220Z","created":"2015-09-08T17:48:34.378Z","3.1.0-full-redirect-1":"2015-09-08T17:48:34.378Z","2.1.0-full-redirect-1":"2015-09-08T19:09:48.738Z","2.2.0-full-redirect-1":"2015-09-08T19:29:50.388Z"},"homepage":"https://github.com/hapijs/hapi-auth-cookie#readme","keywords":["hapi","plugin","auth","cookie","session"],"repository":{"type":"git","url":"git://github.com/hapijs/hapi-auth-cookie.git"},"bugs":{"url":"https://github.com/hapijs/hapi-auth-cookie/issues"},"readmeFilename":"README.md"}