eko/authz-sdk
最新稳定版本:v0.0.1
Composer 安装命令:
composer require eko/authz-sdk
包简介
Authz PHP SDK
README 文档
README
This is the Authz development kit for PHP.
Installation
You can install the SDK in your project by adding the following dependency:
$ composer require eko/authz-sdk
⚠️ Please note that you will need to install the grpc PHP extension.
Usage
You have to instanciate a new Authz Client in your code by doing:
<?php use Eko\AuthzSdk\Client; $client = new Client('localhost:8081', '<client_id>', '<client_secret>');
Once the client is instanciate, you have access to all the gRPC methods.
In order to create a new Principal, you can use
[$response, $status] = $client->PrincipalCreate(new PrincipalCreateRequest([ 'id' => 'user-123', 'attributes' => [ new Attribute(['key' => 'email', 'value' => 'johndoe@acme.tld']), ], ]))->wait();
To declare a new resource:
[$response, $status] = $client->ResourceCreate(new ResourceCreateRequest([ 'id' => 'post.123', 'kind' => 'post', 'value' => '123', 'attributes' => [ new Attribute(['key' => 'owner_email', 'value' => 'johndoe@acme.tld']), ], ]))->wait();
You can also declare a new policy this way:
[$response, $status] = $client->PolicyCreate(new PolicyCreateRequest([ 'id' => 'post-owners', 'resources' => ['post.*'], 'actions' => ['edit', 'delete'], 'attribute_rules' => [ 'principal.email == resource.owner_email', ], ]))->wait();
Then, you can perform a check with:
if ($client->IsAllowed('user-123', 'post', '123', 'edit')) { // Do something }
Please note that you have access to all the gRPC methods declared here in the proto file.
Configuration
This SDK connects over gRPC to the backend service. Here are the available configuration options:
| Property | Description |
|---|---|
| Address | Authz backend to connect to |
| ClientID | Your service account client id used to authenticate |
| ClientSecret | Your service account client secret key used to authenticate |
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-01-14