Permify Php Library
Use Permify in server-side PHP Projects.
What is Permify?
Permify is a plug-&-play authorization API that helps dev teams create granular access control and user management systems without breaking a sweat!
You can easily create complex and flexible RBAC and ABAC solutions without dealing with any learning curve.
Installation
You can install the package via composer:
composer require permify/permify-php
Setup
To get started, create the Permify client using your workspace id and API private token:
use Permify\Client;
$client = new Client("workspace_id", "private_token");
Documentation and Usage Instructions
See the documentation for usage instructions.
An example for better understanding of Permify with the IsAuthorized function
IsAuthorized
This method returns a decision about whether the user is authorized for this action with the given parameters.
Parameters
PolicyName
(mandatory)
Custom Permify Policy name.
UserID
(mandatory)
Id of the User
ResourceID
(optional)
Id of the Resource, mandatory if any resource used or accessed when creating Rule/Rules.
ResourceType
(optional)
Type or name of the Resource, mandatory if any resource used or accessed when creating Rule/Rules.
use Permify\Requests\IsAuthorized;
$isAuthz = $client->call(new IsAuthorized("post-edit", "1", ["resource_id"=> "1", "resource_type" => "posts"]));
echo (int) $isAuthz->allow;
Error handling
For the sake of brevity, the doc instructions omit exception handling. However, various exceptions can occur while processing request, for example because of adding an already existing user or because of timeout.
Example:
use Permify\Requests;
use Permify\Exceptions;
try
{
$resource = $client->send(
new CreateResource("group_id", "resource_type", ["id" => "resource_id", "attributes" => ["custom attribute" => "custom"]])
);
}
catch(Exceptions\ApiTimeoutException $e)
{
//Handle timeout => use fallback
}
catch(Exceptions\ResponseException $e)
{
//Handle errorneous request => use fallback
}
catch(Exceptions\PermifyException $e)
{
//PermifyException is parent of both ResponseException and ApiTimeoutException
}
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] or [email protected] instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.