{"id":19039623,"url":"https://github.com/windwalker-io/authorisation","last_synced_at":"2026-05-07T22:30:15.777Z","repository":{"id":75895392,"uuid":"62501328","full_name":"windwalker-io/authorisation","owner":"windwalker-io","description":"[DEPRECATED] Simple ACL package, inspired by Laravel.","archived":false,"fork":false,"pushed_at":"2023-07-18T08:36:16.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-02T06:44:52.252Z","etag":null,"topics":["acl","acl-library","auth","authorisation","authorization"],"latest_commit_sha":null,"homepage":"https://github.com/ventoviro/windwalker","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/windwalker-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2016-07-03T14:55:06.000Z","updated_at":"2024-12-16T07:16:23.000Z","dependencies_parsed_at":"2025-01-02T06:45:15.569Z","dependency_job_id":"77891c67-c15a-4cc8-8d4a-0ee835293b6b","html_url":"https://github.com/windwalker-io/authorisation","commit_stats":null,"previous_names":[],"tags_count":58,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/windwalker-io%2Fauthorisation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/windwalker-io%2Fauthorisation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/windwalker-io%2Fauthorisation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/windwalker-io%2Fauthorisation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/windwalker-io","download_url":"https://codeload.github.com/windwalker-io/authorisation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240100117,"owners_count":19747632,"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":["acl","acl-library","auth","authorisation","authorization"],"created_at":"2024-11-08T22:17:56.279Z","updated_at":"2026-05-07T22:30:15.725Z","avatar_url":"https://github.com/windwalker-io.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Windwalker Authorisation\n\n## Installation via Composer\n\nAdd this to the require block in your `composer.json`.\n\n``` json\n{\n    \"require\": {\n        \"windwalker/authorisation\": \"~3.0\"\n    }\n}\n```\n\n## Create Authorisation and add policies\n\nA simple example to use Closure as policy with action name `can.edit.article`.\n\n``` php\nuse Windwalker\\Authorisation\\Authorisation;\n\n$auth = new Authorisation;\n\n$auth-\u003eaddPolicy('can.edit.article', function (User $user, \\stdClass $article)\n{\n    return $user-\u003eisAdmin() || $user-\u003eid == $article-\u003eauthor_id;\n});\n\n// Check access\n$auth-\u003eauthorise('can.edit.article', $user, $article); // boolean\n```\n\n## Use Authorisation to Make ACL system\n\nWe can also use `Authorisation` object as a ACL handler, see this example. We find `blog.article` actions from `acl_list`\ntable in database, and check the `can.edit` action greater then `1`, so it means this user (or group) has access\nto edit all articles in blog.\n\n``` php\n$auth-\u003eaddPolicy('can.edit', function (User $user, $assetName)\n{\n    $action = $db-\u003eprepare('SELECT access FROM acl_list WHERE action = :action AND asset = :asset AND group = :group')\n        -\u003ebind('action', 'can.edit')\n        -\u003ebind('asset', $assetName)\n        -\u003ebind('group', $user-\u003egroup_id)\n        -\u003eexecute()\n        -\u003efetchObject();\n\n    return $action \u003e= 1;\n});\n\n// Can edit articles\n$auth-\u003eauthorise('can.edit', $user, 'blog.article'); // boolean\n\n// Can edit article with id = 3\n$auth-\u003eauthorise('can.edit', $user, 'blog.article.3'); // boolean\n```\n\n\u003e NOTE: This is just an simple example to show how ACL works, you must write your own rules to implements ACL system.\n\n## Pre-defined Policy\n\nWe can define a policy by creating classes which implements `PolicyInterface`.\n\n``` php\nclass CanEditPolicy implements \\Windwalker\\Authorisation\\PolicyInterface\n{\n\tpublic function authorise($user, $data = null)\n\t{\n\t\treturn $user-\u003eisAdmin() || $user-\u003eid == $data-\u003eauthor_id;\n\t}\n}\n\n$auth-\u003eaddPolicy('can.edit', new CanEditPolicy);\n\n// After PHP 5.5, you can simply use ::class to add class name\n$auth-\u003eaddPolicy('can.edit', CanEditPolicy::class);\n```\n\n## Register Multiple Policies\n\nUse Policy Provider, we can define policies in a class that is more easily to add multiple policies.\n\n``` php\nuse Windwalker\\Authorisation\\AuthorisationInterface;\nuse Windwalker\\Authorisation\\PolicyProviderInterface;\n\nclass ArticlePolicyProvider implements PolicyProviderInterface\n{\n\tpublic function register(AuthorisationInterface $auth)\n\t{\n\t\t$auth-\u003eaddPolicy('can.create.article', function () { ... });\n\t\t$auth-\u003eaddPolicy('can.edit.article', function () { ... });\n\t\t$auth-\u003eaddPolicy('can.edit.own.article', function () { ... });\n\t\t$auth-\u003eaddPolicy('can.delete.article', function () { ... });\n\t}\n}\n\n// Register policies\n$auth-\u003eregisterPolicyProvider(new ArticlePolicyProvider);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwindwalker-io%2Fauthorisation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwindwalker-io%2Fauthorisation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwindwalker-io%2Fauthorisation/lists"}