{"id":24016325,"url":"https://github.com/decodelabs/cipher","last_synced_at":"2025-07-21T10:05:55.880Z","repository":{"id":209444224,"uuid":"724007814","full_name":"decodelabs/cipher","owner":"decodelabs","description":"PHP tools and systems to interact with JWTs","archived":false,"fork":false,"pushed_at":"2025-06-06T14:06:15.000Z","size":39,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-06-22T05:48:00.506Z","etag":null,"topics":["jwt","middleware","php","psr-15"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/decodelabs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2023-11-27T07:53:42.000Z","updated_at":"2025-06-06T14:06:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"aaa8ef4a-2d54-4a5b-bba0-2e9c2bb65570","html_url":"https://github.com/decodelabs/cipher","commit_stats":null,"previous_names":["decodelabs/cipher"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/decodelabs/cipher","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decodelabs%2Fcipher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decodelabs%2Fcipher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decodelabs%2Fcipher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decodelabs%2Fcipher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/decodelabs","download_url":"https://codeload.github.com/decodelabs/cipher/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decodelabs%2Fcipher/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266278376,"owners_count":23904041,"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":["jwt","middleware","php","psr-15"],"created_at":"2025-01-08T08:48:57.754Z","updated_at":"2025-07-21T10:05:55.863Z","avatar_url":"https://github.com/decodelabs.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cipher\n\n[![PHP from Packagist](https://img.shields.io/packagist/php-v/decodelabs/cipher?style=flat)](https://packagist.org/packages/decodelabs/cipher)\n[![Latest Version](https://img.shields.io/packagist/v/decodelabs/cipher.svg?style=flat)](https://packagist.org/packages/decodelabs/cipher)\n[![Total Downloads](https://img.shields.io/packagist/dt/decodelabs/cipher.svg?style=flat)](https://packagist.org/packages/decodelabs/cipher)\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/decodelabs/cipher/integrate.yml?branch=develop)](https://github.com/decodelabs/cipher/actions/workflows/integrate.yml)\n[![PHPStan](https://img.shields.io/badge/PHPStan-enabled-44CC11.svg?longCache=true\u0026style=flat)](https://github.com/phpstan/phpstan)\n[![License](https://img.shields.io/packagist/l/decodelabs/cipher?style=flat)](https://packagist.org/packages/decodelabs/cipher)\n\n### Tools and systems to interact with JWTs\n\nCipher provides an integrated suite of tools for working with JWTs, including a simple interface for creating and verifying tokens, and a set of middleware for use with [Harvest](https://github.com/decodelabs/harvest), [Greenleaf](https://github.com/decodelabs/greenleaf), or any other PSR-15 compatible middleware stack.\n\n---\n\n## Installation\n\nInstall via Composer:\n\n```bash\ncomposer require decodelabs/cipher\n```\n\n## Usage\n\n### Codec\n\nThe `Codec` class provides the means to encode and decode JWTs.\nThe class requires an instance of `DecodeLabs\\Cipher\\Config` to be passed to the constructor - we provide a default [Dovetail](https://github.com/decodelabs/dovetail) implementation for this, but you can use your own if you wish.\n\nThe config defines what secret and algorithm is used.\n\n```php\nuse DecodeLabs\\Cipher\\Codec;\nuse DecodeLabs\\Dovetail;\n\n$codec = new Codec(\n    Dovetail::load('Cipher')\n);\n\n$payload = $codec-\u003edecode($token);\n```\n\n### Payload\n\nThe `Payload` interface defines a simple wrapper around JWT payload data with `ArrayAccess` support. The `Factory` will instantiate a `Generic` payload for unrecognized issuers, however extended implementations for specific issuers can be created and used instead, providing formal access to custom claim data.\n\n```php\n// $payload['iss'] = 'https://abcdefg.supabase.co/auth/v1'\n// $payload instance of DecodeLabs\\Cipher\\Payload\\Supabase\n$email = $payload-\u003egetEmail();\n$provider = $payload-\u003egetProvider();\n```\n\n### Middleware\n\nCipher provides a set of middleware for use with [Harvest](https://github.com/decodelabs/harvest) or [Greenleaf](https://github.com/decodelabs/greenleaf), or any other PSR-15 compatible middleware stack.\n\nWith the Middleware in your PSR-15 stack, Cipher will attempt to load a JWT from the request, and if successful, will set the `jwt.payload` attribute on the request with the decoded payload.\n\n```php\n$payload = $request-\u003egetAttribute('jwt.payload');\n```\n\nIf using [Greenleaf](https://github.com/decodelabs/greenleaf), the payload can be injected into your action automatically via [Slingshot](https://github.com/decodelabs/slingshot), (below example uses `Supabase` payload):\n\n```php\nuse DecodeLabs\\Cipher\\Payload\\Supabase;\nuse DecodeLabs\\Greenleaf\\Action;\nuse DecodeLabs\\Greenleaf\\Action\\ByMethodTrait;\nuse DecodeLabs\\Harvest;\nuse DecodeLabs\\Harvest\\Response;\n\nclass MySecureAction implements Action\n{\n    use ByMethodTrait;\n\n    public const Middleware = [\n        'Jwt' =\u003e [\n            'required' =\u003e true\n        ]\n    ];\n\n    public function get(\n        Supabase $payload\n    ): Response {\n        return Harvest::json([\n            'email' =\u003e $payload-\u003egetEmail()\n        ]);\n    }\n}\n```\n\n## Licensing\n\nCipher is licensed under the MIT License. See [LICENSE](./LICENSE) for the full license text.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdecodelabs%2Fcipher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdecodelabs%2Fcipher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdecodelabs%2Fcipher/lists"}