Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/php-casbin/casbin-client
PHP's client for Casbin-Server. Casbin-Server is the Access Control as a Service (ACaaS) solution based on Casbin.
https://github.com/php-casbin/casbin-client
access-control acl authorization client rbac server
Last synced: about 4 hours ago
JSON representation
PHP's client for Casbin-Server. Casbin-Server is the Access Control as a Service (ACaaS) solution based on Casbin.
- Host: GitHub
- URL: https://github.com/php-casbin/casbin-client
- Owner: php-casbin
- License: apache-2.0
- Created: 2018-11-14T03:08:45.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-18T12:10:04.000Z (6 months ago)
- Last Synced: 2024-11-07T15:52:13.159Z (11 days ago)
- Topics: access-control, acl, authorization, client, rbac, server
- Language: PHP
- Homepage:
- Size: 20.1 MB
- Stars: 6
- Watchers: 5
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
PHP client for Casbin Server
====[![Latest Stable Version](https://poser.pugx.org/casbin/casbin-client/v/stable)](https://packagist.org/packages/casbin/casbin-client)
[![Total Downloads](https://poser.pugx.org/casbin/casbin-client/downloads)](https://packagist.org/packages/casbin/casbin-client)
[![License](https://poser.pugx.org/casbin/casbin-client/license)](https://packagist.org/packages/casbin/casbin-client)
[![Discord](https://img.shields.io/discord/1022748306096537660?logo=discord&label=discord&color=5865F2)](https://discord.gg/S5UjpzGZjN)``Casbin-client`` is PHP's client for [Casbin-Server](https://github.com/casbin/casbin-server). ``Casbin-Server`` is the ``Access Control as a Service (ACaaS)`` solution based on [Casbin](https://github.com/casbin/casbin).
## Prerequisites
* `php` 5.5 or above, 7.0 or above
* `gRPC` PHP extensionThis guide gets you started with gRPC in PHP with a simple working example:[gRPC in PHP](https://grpc.io/docs/quickstart/php.html).
## Installation
```
composer require casbin/casbin-client
```## Examples
### Client
```php
require_once './vendor/autoload.php';use Proto\CasbinClient;
use Proto\NewEnforcerRequest;
use Proto\NewAdapterRequest;
use Proto\EnforceRequest;$client = new CasbinClient('localhost:50051', [
'credentials' => Grpc\ChannelCredentials::createInsecure(),
]);
```### AdapterRequest
```php
$newAdapterRequest = new NewAdapterRequest();
$newAdapterRequest->setDriverName('file');
$newAdapterRequest->setConnectString('path/to/rbac_policy.csv');list($newAdapterReply, $status) = $client->NewAdapter($newAdapterRequest)->wait();
if (0 !== $status->code) {
throw new \Exception($status->details, $status->code);
}
$adapterHandle = $newAdapterReply->getHandler();
```### EnforcerRequest
```php
$newEnforcerRequest = new NewEnforcerRequest();
$newEnforcerRequest->setModelText(<<setAdapterHandle($adapterHandle);list($newEnforcerReply, $status) = $client->NewEnforcer($newEnforcerRequest)->wait();
if (0 !== $status->code) {
throw new \Exception($status->details, $status->code);
}
```### EnforceRequest
```php
$enforceRequest = new EnforceRequest();
$enforceRequest->setEnforcerHandler($newEnforcerReply->getHandler());
$enforceRequest->setParams(['alice', 'data1', 'read']);list($enforceReply, $status) = $client->Enforce($enforceRequest)->wait();
if (0 !== $status->code) {
throw new \Exception($status->details, $status->code);
}if ($enforceReply->getRes()) {
// permit alice to read data1
} else {
// deny the request, show an error
}```
## License
This project is under Apache 2.0 License. See the [LICENSE](LICENSE) file for the full license text.