Download the PHP package andrewdyer/auth-gate without Composer
On this page you can find all versions of the php package andrewdyer/auth-gate. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download andrewdyer/auth-gate
More information about andrewdyer/auth-gate
Files in andrewdyer/auth-gate
Package auth-gate
Short Description A framework-agnostic library for defining abilities and enforcing authorisation checks against an authenticated user
License MIT
Homepage https://github.com/andrewdyer/auth-gate
Informations about the package auth-gate
Auth Gate
A framework-agnostic library for defining abilities and enforcing authorisation checks against an authenticated user.
Introduction
This library lets you register named ability callbacks and evaluate them against the authenticated user who is performing the action. It supports global before callbacks for overrides, checks for single or multiple abilities, and an explicit authorisation flow that throws an unauthorised exception when checks fail. Undefined abilities and invalid before callback return values are also surfaced through typed exceptions.
Prerequisites
Installation
Getting Started
1. Implement the actor
Any class that represents an authenticated actor must implement the Authenticatable interface. This is the object that will be evaluated against your defined abilities.
2. Create a Gate instance
Instantiate the Gate with the authenticated actor. This instance will be used to define and evaluate abilities.
Usage
The following examples demonstrate the available gate operations using the setup above.
Defining Abilities
Abilities are registered via the define method, which accepts an ability name and a callback that returns a boolean.
Checking Abilities
Use allows and denies to evaluate a single ability, or all and any for multiple abilities.
Authorising Actions
authorize throws an UnauthorizedException if the actor lacks any of the given abilities.
Registering Before Callbacks
Before callbacks run prior to all ability checks. Returning true or false short-circuits the evaluation; returning null (or nothing) defers to the defined ability.
License
Licensed under the MIT license and is free for private or commercial projects.