{"id":20426535,"url":"https://github.com/futurestudio/hapi-auth-multiple-strategies","last_synced_at":"2025-04-12T19:08:55.346Z","repository":{"id":34081373,"uuid":"164655210","full_name":"futurestudio/hapi-auth-multiple-strategies","owner":"futurestudio","description":"A hapi plugin to require multiple authentication strategies","archived":false,"fork":false,"pushed_at":"2024-01-25T12:42:48.000Z","size":239,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-12T19:08:41.247Z","etag":null,"topics":["auth","authentication","future-studio-university","hapi","hapi-auth","hapi-plugin","hapijs","multiple-strategies"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/futurestudio.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-08T13:30:29.000Z","updated_at":"2024-01-12T18:08:08.000Z","dependencies_parsed_at":"2023-01-16T22:45:46.423Z","dependency_job_id":"b8eeb7f6-1968-431c-96bc-601ce13ee88e","html_url":"https://github.com/futurestudio/hapi-auth-multiple-strategies","commit_stats":{"total_commits":207,"total_committers":7,"mean_commits":"29.571428571428573","dds":0.6908212560386473,"last_synced_commit":"5b42a6b006c462c577efa65b9f6d11a3c8279f4a"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/futurestudio%2Fhapi-auth-multiple-strategies","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/futurestudio%2Fhapi-auth-multiple-strategies/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/futurestudio%2Fhapi-auth-multiple-strategies/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/futurestudio%2Fhapi-auth-multiple-strategies/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/futurestudio","download_url":"https://codeload.github.com/futurestudio/hapi-auth-multiple-strategies/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248618277,"owners_count":21134200,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["auth","authentication","future-studio-university","hapi","hapi-auth","hapi-plugin","hapijs","multiple-strategies"],"created_at":"2024-11-15T07:16:50.670Z","updated_at":"2025-04-12T19:08:55.316Z","avatar_url":"https://github.com/futurestudio.png","language":"JavaScript","readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg\n    width=\"571\" style=\"max-width:100%;\"\n    src=\"https://github.com/futurestudio/hapi-auth-multiple-strategies/blob/master/media/hapi-auth-multiple-strategies.png?raw=true\"\n    alt=\"hapi-auth-multiple-strategies logo\"\u003e\n  \u003cbr/\u003e\n  \u003cbr/\u003e\n  \u003cp\u003e\n    Require multiple authentication strategies in hapi.\n  \u003c/p\u003e\n  \u003cbr/\u003e\n  \u003cp\u003e\n    \u003ca href=\"#installation\"\u003e\u003cstrong\u003eInstallation\u003c/strong\u003e\u003c/a\u003e ·\n    \u003ca href=\"#usage\"\u003e\u003cstrong\u003eUsage\u003c/strong\u003e\u003c/a\u003e ·\n    \u003ca href=\"#authentication-strategy-options\"\u003e\u003cstrong\u003eStrategy Options\u003c/strong\u003e\u003c/a\u003e\n  \u003c/p\u003e\n  \u003cbr/\u003e\n  \u003cbr/\u003e\n  \u003cp\u003e\n    \u003ca href=\"https://travis-ci.org/futurestudio/hapi-auth-multiple-strategies\"\u003e\u003cimg src=\"https://travis-ci.org/futurestudio/hapi-auth-multiple-strategies.svg?branch=master\" alt=\"Build Status\" data-canonical-src=\"https://travis-ci.org/futurestudio/hapi-auth-multiple-strategies.svg?branch=master\" style=\"max-width:100%;\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://snyk.io/test/github/futurestudio/hapi-auth-multiple-strategies\"\u003e\u003cimg src=\"https://snyk.io/test/github/futurestudio/hapi-auth-multiple-strategies/badge.svg\" alt=\"Known Vulnerabilities\" data-canonical-src=\"https://snyk.io/test/github/futurestudio/hapi-auth-multiple-strategies\" style=\"max-width:100%;\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://www.npmjs.com/package/hapi-auth-multiple-strategies\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/hapi-auth-multiple-strategies.svg\" alt=\"hapi-auth-multiple-strategies Version\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://www.npmjs.com/package/hapi-auth-multiple-strategies\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/hapi-auth-multiple-strategies.svg\" alt=\"Total downloads\"\u003e\u003c/a\u003e\n  \u003c/p\u003e\n  \u003cp\u003e\n    \u003cem\u003eFollow \u003ca href=\"http://twitter.com/marcuspoehls\"\u003e@marcuspoehls\u003c/a\u003e for updates!\u003c/em\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\n------\n\n\u003cp align=\"center\"\u003e\u003csup\u003eThe \u003ca href=\"https://futurestud.io\"\u003eFuture Studio University\u003c/a\u003e supports development of this hapi plugin 🚀\u003c/sup\u003e\n\u003cbr\u003e\u003cb\u003e\nJoin the \u003ca href=\"https://futurestud.io/university\"\u003eFuture Studio University and Skyrocket in Node.js\u003c/a\u003e\u003c/b\u003e\n\u003c/p\u003e\n\n------\n\n\n## Introduction\nAdd `hapi-auth-multiple-strategies` in your hapi project to authenticate a request against multiple authentication strategies. Hapi allows you to define multiple auth strategies on a route, but this requires only a single strategy to authenticate the request. In contrast, `hapi-auth-multiple-strategies` requires all strategies to be successful.\n\n\n## Installation\nAdd `hapi-auth-multiple-strategies` as a dependency to your project:\n\n```bash\nnpm i hapi-auth-multiple-strategies\n```\n\n\n## Requirements\n\u003e **hapi v19 (or later)** and **Node.js v12 (or newer)**\n\nThis plugin requires **hapi v19** (or later) and **Node.js v12 or newer**.\n\n\n### Compatibility\n| Major Release | [hapi.js](https://github.com/hapijs/hapi) version | Node.js version |\n| --- | --- | --- |\n| `v3` | `\u003e=18 hapi` | `\u003e=12` |\n| `v2` | `\u003e=18 hapi` | `\u003e=8` |\n| `v1` | `\u003e=17 hapi` | `\u003e=8` |\n\n\n## Usage\nRegister `hapi-auth-multiple-strategies` to your hapi server. This will add the `multiple-strategies` authentication scheme to your hapi server.\n\n```js\nawait server.register({\n  plugin: require('hapi-auth-multiple-strategies')\n})\n\n// went smooth like chocolate :)\n// now your hapi server supports the 'multiple-strategies' auth scheme\n```\n\nThen declare a new authentication strategy base on the `multiple-strategies` scheme and pass in all required `strategies`.\n\n```js\n// Assuming you have the following strategies your server\nserver.auth.strategy('jwt', 'bearer', options);\nserver.auth.strategy('jwt-refresh', 'token', options);\n\n// create a new strategy that requires both 'jwt' strategies\nserver.auth.strategy('jwt-all-in', 'multiple-strategies', {\n  strategies: ['jwt', 'jwt-refresh']\n});\n\n// use the 'jwt-all-in' strategy on your route\nserver.route({\n  method: 'GET',\n  path: '/api/logout',\n  config: {\n    auth: 'jwt-all-in',\n    handler: () =\u003e 'hey bud, you’re logged out'\n  }\n});\n```\n\nThe `jwt-all-in` strategy ensures that an incoming request satisfies both strategies, `jwt` and `jwt-refresh`.\n\nIf a request doesn’t authenticate with one or more of the strategies, it will return unauthenticated.\n\n\n## Authentication Strategy Options\nWhen creating a new authentication strategy using the `multiple-strategies` scheme, you’re required to pass in an array of the authentication strategy names that are required.\n\n- **`strategies`**: (Array), required\n  - an array of auth strategy names against a request will be authenticated\n\n\n## Credentials \u0026 Scope\nTypically the `request.auth.credentials` is populated with the credentials from a single strategy. When testing multiple strategies, you’ll get the credentials from all strategies.\n\nWhen a request passes all authentication strategies, the related credentials are assigned to the strategy’s name in `request.auth.credentials`.\n\nBecause hapi authorizes requests via the `scope` property, you’ll find the aggregated scope from all strategies in the credentials as well.\n\nHere’s a sample result of `request.auth.credentials`:\n\n```js\n{\n  jwt: { name: 'Marcus', scope: [ 'admin' ] }\n  'jwt-refresh': { username: 'marcus', name: 'Marcus', scope: [ 'user' ] }\n  scope: [ 'admin', 'user' ]\n});\n```\n\nEnjoy!\n\n\n## Links \u0026 Resources\n\n- [hapi tutorial series](https://futurestud.io/tutorials/hapi-get-your-server-up-and-running) with 100+ tutorials\n\n\n## Contributing\n\n1.  Create a fork\n2.  Create your feature branch: `git checkout -b my-feature`\n3.  Commit your changes: `git commit -am 'Add some feature'`\n4.  Push to the branch: `git push origin my-new-feature`\n5.  Submit a pull request 🚀\n\n\n## License\n\nMIT © [Future Studio](https://futurestud.io)\n\n---\n\n\u003e [futurestud.io](https://futurestud.io) \u0026nbsp;\u0026middot;\u0026nbsp;\n\u003e GitHub [@futurestudio](https://github.com/futurestudio/) \u0026nbsp;\u0026middot;\u0026nbsp;\n\u003e Twitter [@futurestud_io](https://twitter.com/futurestud_io)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuturestudio%2Fhapi-auth-multiple-strategies","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffuturestudio%2Fhapi-auth-multiple-strategies","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuturestudio%2Fhapi-auth-multiple-strategies/lists"}