{"id":26647337,"url":"https://github.com/ptondereau/ext-biscuit","last_synced_at":"2026-04-16T19:44:51.818Z","repository":{"id":284006834,"uuid":"876350929","full_name":"ptondereau/ext-biscuit","owner":"ptondereau","description":"WIP - a PHP extension for biscuit token implementation","archived":false,"fork":false,"pushed_at":"2025-03-27T15:36:49.000Z","size":88,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-19T05:06:01.173Z","etag":null,"topics":["biscuit","extension","php","security"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ptondereau.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-21T20:23:43.000Z","updated_at":"2025-03-27T15:36:30.000Z","dependencies_parsed_at":"2025-03-23T16:38:14.550Z","dependency_job_id":"a2083c88-cb19-454b-92e3-d7c04e148b5d","html_url":"https://github.com/ptondereau/ext-biscuit","commit_stats":null,"previous_names":["ptondereau/ext-biscuit"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ptondereau/ext-biscuit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ptondereau%2Fext-biscuit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ptondereau%2Fext-biscuit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ptondereau%2Fext-biscuit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ptondereau%2Fext-biscuit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ptondereau","download_url":"https://codeload.github.com/ptondereau/ext-biscuit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ptondereau%2Fext-biscuit/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260690832,"owners_count":23047099,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["biscuit","extension","php","security"],"created_at":"2025-03-24T23:51:46.112Z","updated_at":"2026-04-16T19:44:46.753Z","avatar_url":"https://github.com/ptondereau.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e [!WARNING]  \n\u003e The PHP extension is still ine BETA and maybe not suitable for production for now\n\n# PHP Biscuit Extension\n\nThis extension provides PHP bindings for the [Biscuit](https://github.com/biscuit-auth/biscuit) authorization library. Biscuit is a bearer token format with decentralized verification and offline attenuation.\n\n## Requirements\n\n- PHP 8.1.0 or later (up to PHP 8.4)\n- Biscuit library installed on your system (libbiscuit_auth.so) if you want to build it from sources\n\n\u003e [!IMPORTANT]  \n\u003e We doesn't support Windows build for the moment\n\n## API not available\n\n- [ThirdParty block](https://doc.biscuitsec.org/reference/specifications#appending-a-third-party-block)\n\n## Installation\n\n1. Ensure the Biscuit library is installed:\n\nIf not, you can download the library with your corresponding OS and architecture here: https://github.com/eclipse-biscuit/biscuit-rust/releases\n\n2. Build and install the extension:\n```bash\nphpize\n./configure --with-biscuit\nmake\nsudo make install\n```\n\n3. Add the extension to your php.ini:\n```ini\nextension=biscuit.so\n```\n\n## Usage\n\n### Creating a Key Pair\n\n```php\n$seed = random_bytes(32); // or any string\n$kp = new BiscuitKeyPair($seed, BISCUIT_ALGORITHM_ED25519);\n\n// Get the public key\n$publicKey = $kp-\u003egetPublicKey();\n```\n\n### Building a Token\n\n```php\n// Create a builder\n$builder = new BiscuitBuilder();\n\n// Set context (optional)\n$builder-\u003esetContext('app_v1');\n\n// Add facts and rules\n$builder-\u003eaddFact('user(\"1234\")');\n$builder-\u003eaddFact('right(\"read\")');\n$builder-\u003eaddRule('allow($user, $right) \u003c- user($user), right($right)');\n\n// Add a check (optional)\n$builder-\u003eaddCheck('check if user($id), $id == \"1234\"');\n\n// Build the token (with optional random seed)\n$seed = random_bytes(32);\n$token = $builder-\u003ebuild($kp, $seed);\n```\n\n### Adding Blocks\n\n```php\n// Create a block builder\n$blockBuilder = new BiscuitBlockBuilder();\n\n// Set context (optional)\n$blockBuilder-\u003esetContext('block_v1');\n\n// Add facts and rules to the block\n$blockBuilder-\u003eaddFact('resource(\"file1.txt\")');\n$blockBuilder-\u003eaddRule('can_access($user, $resource) \u003c- user($user), resource($resource)');\n\n// Append the block to the token\n$newToken = $token-\u003eappendBlock($blockBuilder, $kp);\n```\n\n### Authorization\n\n```php\n// Create an authorizer\n$authorizer = $token-\u003ecreateAuthorizer();\n\n// Alternatively, use the builder pattern\n$authBuilder = new BiscuitAuthorizerBuilder();\n$authBuilder-\u003eaddFact('current_time(\"14:30\")')\n    -\u003eaddRule('during_business_hours($time) \u003c- $time \u003e= \"09:00\", $time \u003c= \"17:00\"')\n    -\u003eaddPolicy('allow if can_access($user, $resource), during_business_hours($time)');\n$authorizer = $authBuilder-\u003ebuild($token);\n\n// Check authorization\nif ($authorizer-\u003eauthorize()) {\n    echo \"Access granted\\n\";\n} else {\n    echo \"Access denied: \" . biscuit_error_message() . \"\\n\";\n}\n```\n\n### Serialization\n\n```php\n// Serialize a key pair\n$serializedKp = $kp-\u003eserialize();\n$deserializedKp = BiscuitKeyPair::deserialize($serializedKp, BISCUIT_ALGORITHM_ED25519);\n\n// Serialize a public key\n$serializedPk = $publicKey-\u003eserialize();\n$deserializedPk = BiscuitPublicKey::deserialize($serializedPk, BISCUIT_ALGORITHM_ED25519);\n\n// Serialize a token\n$serializedToken = $token-\u003eserialize();\n\n// Serialize a token in sealed mode\n$sealedToken = $token-\u003eserializeSealed();\n$deserializedToken = BiscuitToken::fromSealed($sealedToken, $publicKey);\n```\n\n### Inspection and Debugging\n\n```php\n// Print token information\necho $token-\u003eprint();\n\n// Get block source\necho $token-\u003eprintBlockSource(0); // Print the first block\n\n// Get block count\n$blockCount = $token-\u003eblockCount();\n\n// Get block context\n$context = $token-\u003eblockContext(1); // Get context of the second block\n\n// Print authorizer state\necho $authorizer-\u003eprint();\n```\n\n## Testing\n\nRun the test suite:\n```bash\nmake test\n```\n\n## License\n\nThis extension is released under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fptondereau%2Fext-biscuit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fptondereau%2Fext-biscuit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fptondereau%2Fext-biscuit/lists"}