{"id":39455926,"url":"https://github.com/zakodium/adonis-authorization","last_synced_at":"2026-01-18T04:35:51.307Z","repository":{"id":55882992,"uuid":"319568900","full_name":"zakodium/adonis-authorization","owner":"zakodium","description":"Authorization provider for AdonisJS 5","archived":false,"fork":false,"pushed_at":"2020-12-09T17:34:02.000Z","size":36,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-20T10:41:48.856Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/zakodium.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}},"created_at":"2020-12-08T08:06:03.000Z","updated_at":"2020-12-09T17:33:45.000Z","dependencies_parsed_at":"2022-08-15T08:31:32.430Z","dependency_job_id":null,"html_url":"https://github.com/zakodium/adonis-authorization","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/zakodium/adonis-authorization","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zakodium%2Fadonis-authorization","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zakodium%2Fadonis-authorization/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zakodium%2Fadonis-authorization/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zakodium%2Fadonis-authorization/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zakodium","download_url":"https://codeload.github.com/zakodium/adonis-authorization/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zakodium%2Fadonis-authorization/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28529846,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T00:39:45.795Z","status":"online","status_checked_at":"2026-01-18T02:00:07.578Z","response_time":98,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2026-01-18T04:35:50.604Z","updated_at":"2026-01-18T04:35:51.302Z","avatar_url":"https://github.com/zakodium.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Adonis Authorization\n\n[![NPM version][npm-image]][npm-url]\n[![build status][ci-image]][ci-url]\n[![npm download][download-image]][download-url]\n\nAuthorization provider for AdonisJS.\n\n| :warning: This module is unstable and in active development. Use at your own risk. |\n| ---------------------------------------------------------------------------------- |\n\n## Prerequisites\n\nThis provider requires Adonis v5 preview and won't work with Adonis v4.\n\n## Installation\n\n```console\nnpm i @zakodium/adonis-authorization\nnode ace invoke @zakodium/adonis-authorization\n```\n\n## Documentation\n\n### Introduction\n\nThe API of this provider is heavily inspired from [Laravel's Authorization feature](https://laravel.com/docs/8.x/authorization),\nthough it was designed a bit differently to take TypeScript types into account.\n\nAuthorization is always asynchronous (returning promises), even if the methods are implemented using synchronous callbacks.\n\n### Gates\n\n#### Defining a gate\n\nA gate is a simple callback function associated with a named action. It must return\na boolean or a Promise that resolves to a boolean. Any other value will be rejected\nand result in a thrown Exception, to avoid security-impacting mistakes.\n\nTo write new gates, add entries to the `Gate.registerActions` call in `start/authorization.ts`:\n\nFor example:\n\n```ts\nimport { Gate } from '@ioc:Adonis/Addons/Authorization';\n\nexport const actions = Gate.registerActions({\n  'some-action': (user) =\u003e {\n    return user.isAdmin;\n  },\n});\n```\n\n##### Gate with parameters\n\nA gate can define any number of parameters, that will be expected to be passed the callback after the user object:\n\n```ts\nimport { Gate, User } from '@ioc:Adonis/Addons/Authorization';\n\nimport Post from 'App/Models/Post';\n\nexport const actions = Gate.registerActions({\n  'some-action': (user, post: Post, requireAdmin: boolean) =\u003e {\n    if (requireAdmin) {\n      return user.isAdmin;\n    } else {\n      return post.userId === user.id;\n    }\n  },\n});\n```\n\nNote that the `user` parameter is typed automatically, but you need to explicitly\ntype the other parameters, otherwise they default to `any`.\n\n##### Gate allowing guests\n\nBy default, gates do not allow guests (unauthenticated users). The gate callback\nis not called and the gate behaves as if the callback returned `false`.\n\nIt is possible to opt into allowing guests, by passing `{ allowGuest: true }` while defining the gate.\nIn that case, the gate callback will be called for guests, with the `user` parameter being `null`.\n\n```ts\nimport { Gate } from '@ioc:Adonis/Addons/Authorization';\n\nexport const actions = Gate.registerActions({\n  'some-action': {\n    allowGuest: true,\n    gate(user) {\n      if (!user) {\n        // We have a guest.\n        return false;\n      }\n      return user.isAdmin;\n    },\n  },\n});\n```\n\n#### Using gates\n\nTODO\n\n### Policies\n\nTODO\n\n## License\n\n[MIT](./LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/@zakodium/adonis-authorization.svg\n[npm-url]: https://www.npmjs.com/package/@zakodium/adonis-authorization\n[ci-image]: https://github.com/zakodium/adonis-authorization/workflows/Node.js%20CI/badge.svg?branch=main\n[ci-url]: https://github.com/zakodium/adonis-authorization/actions?query=workflow%3A%22Node.js+CI%22\n[download-image]: https://img.shields.io/npm/dm/@zakodium/adonis-authorization.svg\n[download-url]: https://www.npmjs.com/package/@zakodium/adonis-authorization\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzakodium%2Fadonis-authorization","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzakodium%2Fadonis-authorization","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzakodium%2Fadonis-authorization/lists"}