{"action":"created","issue":{"url":"https://api.github.com/repos/fastify/fastify/issues/10","repository_url":"https://api.github.com/repos/fastify/fastify","labels_url":"https://api.github.com/repos/fastify/fastify/issues/10/labels{/name}","comments_url":"https://api.github.com/repos/fastify/fastify/issues/10/comments","events_url":"https://api.github.com/repos/fastify/fastify/issues/10/events","html_url":"https://github.com/fastify/fastify/issues/10","id":182036674,"number":10,"title":"Authentication","user":{"login":"mcollina","id":52195,"avatar_url":"https://avatars3.githubusercontent.com/u/52195?v=3","gravatar_id":"","url":"https://api.github.com/users/mcollina","html_url":"https://github.com/mcollina","followers_url":"https://api.github.com/users/mcollina/followers","following_url":"https://api.github.com/users/mcollina/following{/other_user}","gists_url":"https://api.github.com/users/mcollina/gists{/gist_id}","starred_url":"https://api.github.com/users/mcollina/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcollina/subscriptions","organizations_url":"https://api.github.com/users/mcollina/orgs","repos_url":"https://api.github.com/users/mcollina/repos","events_url":"https://api.github.com/users/mcollina/events{/privacy}","received_events_url":"https://api.github.com/users/mcollina/received_events","type":"User","site_admin":false},"labels":[{"id":512976619,"url":"https://api.github.com/repos/fastify/fastify/labels/feature","name":"feature","color":"1d76db","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-10-10T14:57:36Z","updated_at":"2017-03-16T19:33:42Z","closed_at":null,"body":"We need to figure our how authentication would work in fastify.\n"},"comment":{"url":"https://api.github.com/repos/fastify/fastify/issues/comments/287167260","html_url":"https://github.com/fastify/fastify/issues/10#issuecomment-287167260","issue_url":"https://api.github.com/repos/fastify/fastify/issues/10","id":287167260,"user":{"login":"jsumners","id":321201,"avatar_url":"https://avatars2.githubusercontent.com/u/321201?v=3","gravatar_id":"","url":"https://api.github.com/users/jsumners","html_url":"https://github.com/jsumners","followers_url":"https://api.github.com/users/jsumners/followers","following_url":"https://api.github.com/users/jsumners/following{/other_user}","gists_url":"https://api.github.com/users/jsumners/gists{/gist_id}","starred_url":"https://api.github.com/users/jsumners/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jsumners/subscriptions","organizations_url":"https://api.github.com/users/jsumners/orgs","repos_url":"https://api.github.com/users/jsumners/repos","events_url":"https://api.github.com/users/jsumners/events{/privacy}","received_events_url":"https://api.github.com/users/jsumners/received_events","type":"User","site_admin":false},"created_at":"2017-03-16T19:33:42Z","updated_at":"2017-03-16T19:33:42Z","body":"I think this goes with this issue. Let's say you have the following\r\n\r\n```js\r\nfastify.addHook('preHandler', (fastifyRequest, res, next) => {\r\n    let authError\r\n    if (!fastifyRequest.req.headers['authorization']) {\r\n      authError = Error('missing authorization header')\r\n      fastifyRequest.log.error('unauthorized: %s', authError.message)\r\n      res.code(401).send({})\r\n      return next(authError)\r\n    }\r\n    const authKeyParts = fastifyRequest.req.headers['authorization'].split(' ')\r\n    if (authKeyParts.len !== 2 || authKeyParts[0] !== 'bearer') {\r\n      authError = Error('invalid authorization header')\r\n    }\r\n    if (config.authorization.has(authKeyParts[1]) === false) {\r\n      authError = Error('auth key invalid')\r\n    }\r\n    if (authError) {\r\n      fastifyRequest.log.error('unauthorized: %s', authError.message)\r\n      res.code(401).send({})\r\n      return next(authError)\r\n    }\r\n    next()\r\n  })\r\n```\r\n\r\nThe client will never get a `401` because the only way to not send multiple responses is to pass an error into `next()`."}}
{"actor":{"display_login":"jsumners"}}