承接 linkorb/spicedb-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

linkorb/spicedb-php

最新稳定版本:v1.2.1

Composer 安装命令:

composer require linkorb/spicedb-php

包简介

SpiceDB connector for PHP

README 文档

README

Docs

This repository houses the PHP client library for Authzed and SpiceDB.

SpiceDB is a database system for managing security-critical permissions checking.

SpiceDB acts as a centralized service that stores authorization data. Once stored, data can be performantly queried to answer questions such as "Does this user have access to this resource?" and "What are all the resources this user has access to?".

Authzed operates the globally available, serverless database platform for SpiceDB.

Supported client API versions:

You can find more info about the API in the Authzed Documentation API Reference or the Authzed API Buf Registry repository.

Getting Started

We highly recommend following the Protecting Your First App guide to learn the latest best practice to integrate an application with Authzed.

Basic Usage

Installation

Using composer tool run:

composer require linkorb/spicedb-php

Initializing a client

SpiceDB connector depends on symfony/serializer and symfony/http-client. Instantiation of a new client with pure PHP can be done following way:

use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use LinkORB\Authzed\Serializer\JsonLinesDecoder;
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
use Symfony\Component\Serializer\Normalizer\UnwrappingDenormalizer;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;

new SpiceDB(
    new Serializer(
        [new ArrayDenormalizer(), new UnwrappingDenormalizer(), new ObjectNormalizer(null, null, null, new ReflectionExtractor())],
        [new JsonEncoder(), new JsonLinesDecoder()]
    ),
    HttpClient::create(),
    getenv('SPICEDB_HOST'),
    getenv('SPICEDB_API_KEY')
);

For Symfony apps there'll be a separate bundle which is currently WIP

Performing an API call

SpiceDB connector implements communication through REST API. Check LinkORB\Authzed\ConnectorInterface for available methods. Here's example of write schema request:

$client->writeSchema(new \LinkORB\Authzed\Dto\Request\Schema(
    'definition blog/post {
           relation reader: blog/user
           relation writer: blog/user
           permission read = reader + writer
           permission write = writer
    }
    
    definition blog/user {}'
));

Tests

Tests can be run with following command:

make run-test

For that you need to have Docker installed. Alternatively you can run test with PHP installed on host:

phpunit -c ./phpunit.xml --testsuite 'Integration' ./tests/

统计信息

  • 总下载量: 3.23k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-12-29