{"id":20426529,"url":"https://github.com/futurestudio/hapi-authorized-scope","last_synced_at":"2025-07-16T04:37:36.641Z","repository":{"id":35162340,"uuid":"214866799","full_name":"futurestudio/hapi-authorized-scope","owner":"futurestudio","description":"Finds the scope that authorizes a user on a route","archived":false,"fork":false,"pushed_at":"2024-01-25T12:42:43.000Z","size":183,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-15T05:35:46.353Z","etag":null,"topics":["auth","authorization","future-studio-university","hapi","hapi-plugin","hapijs","scope"],"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-10-13T17:53:05.000Z","updated_at":"2024-01-10T20:25:57.000Z","dependencies_parsed_at":"2023-01-16T22:24:19.495Z","dependency_job_id":"827a9cc0-d3ef-4973-96e3-f1eabf830d9c","html_url":"https://github.com/futurestudio/hapi-authorized-scope","commit_stats":{"total_commits":107,"total_committers":4,"mean_commits":26.75,"dds":0.6448598130841121,"last_synced_commit":"2d0e80260b255f9632ae4c72597a28a0276d04c9"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/futurestudio/hapi-authorized-scope","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/futurestudio%2Fhapi-authorized-scope","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/futurestudio%2Fhapi-authorized-scope/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/futurestudio%2Fhapi-authorized-scope/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/futurestudio%2Fhapi-authorized-scope/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/futurestudio","download_url":"https://codeload.github.com/futurestudio/hapi-authorized-scope/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/futurestudio%2Fhapi-authorized-scope/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265481953,"owners_count":23773979,"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","authorization","future-studio-university","hapi","hapi-plugin","hapijs","scope"],"created_at":"2024-11-15T07:16:50.267Z","updated_at":"2025-07-16T04:37:36.622Z","avatar_url":"https://github.com/futurestudio.png","language":"JavaScript","readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg\n    width=\"557\" style=\"max-width:100%;\"\n    src=\"https://github.com/futurestudio/hapi-authorized-scope/blob/master/media/hapi-authorized-scope.png?raw=true\"\n    alt=\"hapi-authorized-scope logo\"\u003e\n  \u003cbr/\u003e\n  \u003cbr/\u003e\n  \u003cp\u003e\n    Determine which scope authorized a user on a route.\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  \u003c/p\u003e\n  \u003cbr/\u003e\n  \u003cbr/\u003e\n  \u003cp\u003e\n    \u003ca href=\"https://travis-ci.com/futurestudio/hapi-authorized-scope\"\u003e\u003cimg src=\"https://travis-ci.com/futurestudio/hapi-authorized-scope.svg?branch=master\" alt=\"Build Status\" data-canonical-src=\"https://travis-ci.com/futurestudio/hapi-authorized-scope.svg?branch=master\" style=\"max-width:100%;\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://www.npmjs.com/package/hapi-authorized-scope\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/hapi-authorized-scope.svg\" alt=\"hapi-authorized-scope Version\"\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\nThe `hapi-authorized-scope` plugin determines and stores the scope that authorized an authenticated request. You'll find the scope authorizing the request in `request.auth.authorizedScope`.\n\nIn hapi, you’ll find all auth-related details in `request.auth`, that’s the reason this plugin adds the `authorizedScope` property there:\n\n```js\n{\n  isAuthenticated: true,\n  isAuthorized: true,\n  credentials: { username: 'marcus', scope: ['admin', 'user'] },\n  artifacts: null,\n  strategy: 'test',\n  mode: 'required',\n  error: null,\n  isInjected: true,\n  authorizedScope: 'user'  // \u003c-- added: the authorized scope that let the user access a route\n}\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| `v2` | `\u003e=17 hapi` | `\u003e=12` |\n| `v1` | `\u003e=17 hapi` | `\u003e=8` |\n\n\n## Installation\nAdd `hapi-authorized-scope` as a dependency to your project:\n\n```bash\nnpm i hapi-authorized-scope\n```\n\n\n## Usage\nThe usage is pretty straightforward: register the plugin to your hapi server and that’s it:\n```js\nawait server.register({\n  plugin: require('hapi-authorized-scope')\n})\n\n// went smooth like chocolate :)\n```\n\n`hapi-authorized-scope` extends the request lifecycle `onPostAuth` and finds the first scope in the authenticated credentials that authorizes the request to access the route.\n\nIn your route handlers or request lifecycle extension points, you may access the authorized scope like this:\n\n```js\n{\n  method: 'GET',\n  path: '/profile',\n  options: {\n    handler: async (request, h) {\n      const authorizedScope = request.auth.authorizedScope\n\n      Logger.debug(`Scope authorizing the user to access this route: ${authorizedScope}`)\n\n      return h.view('profile')\n    }\n  }\n}\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-authorized-scope","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffuturestudio%2Fhapi-authorized-scope","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuturestudio%2Fhapi-authorized-scope/lists"}