{"id":24565980,"url":"https://github.com/steffenbrand/non-static-php-jwt","last_synced_at":"2025-03-17T02:25:19.664Z","repository":{"id":57059486,"uuid":"145980129","full_name":"steffenbrand/non-static-php-jwt","owner":"steffenbrand","description":"non-static wrapper for php-jwt","archived":false,"fork":false,"pushed_at":"2018-08-24T13:59:00.000Z","size":13,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-23T12:17:28.142Z","etag":null,"topics":["jwt","jwt-decode","jwt-encode","jwt-token"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/steffenbrand.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-24T10:51:26.000Z","updated_at":"2018-08-24T13:59:01.000Z","dependencies_parsed_at":"2022-08-24T07:30:32.444Z","dependency_job_id":null,"html_url":"https://github.com/steffenbrand/non-static-php-jwt","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steffenbrand%2Fnon-static-php-jwt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steffenbrand%2Fnon-static-php-jwt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steffenbrand%2Fnon-static-php-jwt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steffenbrand%2Fnon-static-php-jwt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/steffenbrand","download_url":"https://codeload.github.com/steffenbrand/non-static-php-jwt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243960629,"owners_count":20375108,"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","jwt-decode","jwt-encode","jwt-token"],"created_at":"2025-01-23T12:17:42.624Z","updated_at":"2025-03-17T02:25:19.644Z","avatar_url":"https://github.com/steffenbrand.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# non-static-php-jwt\nnon-static-php-jwt is a wrapper for [firebase/php-jwt](https://github.com/firebase/php-jwt) to make it easily mockable\nwith [phpspec/prophecy](https://github.com/phpspec/prophecy) (or any other mocking library) within your phpunit tests.\n\n## Installation\n```\ncomposer require steffenbrand/non-static-php-jwt\n```\n\n## Versioning\nThe releases will match the release versions of [firebase/php-jwt](https://github.com/firebase/php-jwt) starting with ^5.0.  \nThe supported PHP versions will be ^7.1, since return types and type hinting are used in this library.\n\n## Usage\nIt's just a wrapper for [firebase/php-jwt](https://github.com/firebase/php-jwt), so the usage is almost the same, except the fact that you have to create an instance of `\\SteffenBrand\\NonStaticPhpJwt\\Jwt` first.\n\n### Encoding and decoding\n```php\n$jwt = new \\SteffenBrand\\NonStaticPhpJwt\\Jwt();\n\n$key = 'example_key';\n$token = [\n    'iss' =\u003e 'http://example.org',\n    'aud' =\u003e 'http://example.com',\n    'iat' =\u003e 1356999524,\n    'nbf' =\u003e 1357000000\n];\n\n$webToken = $jwt-\u003eencode($token, $key);\n$decoded = $jwt-\u003edecode($webToken, $key, ['HS256']);\n\nvar_dump($decoded);\nprint_r((array) $decoded);\n```\n\n### Adding a leeway\nYou can add a leeway to account for when there is a clock skew times between\nthe signing and verifying servers. It is recommended that this leeway should\nnot be bigger than a few minutes.\n\nSource: http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html#nbfDef\n\nThe leeway if the fourth parameter of the decode method and defaults to `0`.\n```php\n$jwt-\u003edecode($jwt, $key, ['HS256'], $leeway = 60);\n```\n\n### Prophecising\nThe primary goal of this library is to allow prophecising the results of JWT methods within you phpunit tests.\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nnamespace SteffenBrand\\NonStaticPhpJwt\\Test;\n\nuse PHPUnit\\Framework\\TestCase;\nuse Prophecy\\Prophecy\\MethodProphecy;\nuse Prophecy\\Prophecy\\ObjectProphecy;\nuse SteffenBrand\\NonStaticPhpJwt\\Jwt;\n\nclass JwtTest extends TestCase\n{\n    /**\n     * @var Jwt\n     */\n    private $jwt;\n\n    protected function setUp()\n    {\n        parent::setUp();\n        $this-\u003ejwt = $this-\u003eprophesize(Jwt::class);\n    }\n\n    public function getSut(): Dummy\n    {\n        return new Dummy($this-\u003ejwt-\u003ereveal());\n    }\n\n    public function testJwtEncodeCanBeProphecised(): void\n    {\n        $returnValue = 'string';\n        $this-\u003ejwt-\u003eencode([], '')-\u003eshouldBeCalled()-\u003ewillReturn($returnValue);\n\n        $this-\u003eassertInstanceOf(ObjectProphecy::class, $this-\u003ejwt);\n        $this-\u003eassertInstanceOf(MethodProphecy::class, $this-\u003ejwt-\u003egetMethodProphecies('encode')[0]);\n        $this-\u003eassertEquals($returnValue, $this-\u003egetSut()-\u003eencode());\n    }\n\n    public function testJwtDecodeCanBeProphecised(): void\n    {\n        $returnValue = new \\stdClass();\n        $this-\u003ejwt-\u003edecode('', '')-\u003eshouldBeCalled()-\u003ewillReturn($returnValue);\n\n        $this-\u003eassertInstanceOf(ObjectProphecy::class, $this-\u003ejwt);\n        $this-\u003eassertInstanceOf(MethodProphecy::class, $this-\u003ejwt-\u003egetMethodProphecies('decode')[0]);\n        $this-\u003eassertEquals($returnValue, $this-\u003egetSut()-\u003edecode());\n    }\n\n    public function testJwtSignCanBeProphecised(): void\n    {\n        $returnValue = 'string';\n        $this-\u003ejwt-\u003esign('', '')-\u003eshouldBeCalled()-\u003ewillReturn($returnValue);\n\n        $this-\u003eassertInstanceOf(ObjectProphecy::class, $this-\u003ejwt);\n        $this-\u003eassertInstanceOf(MethodProphecy::class, $this-\u003ejwt-\u003egetMethodProphecies('sign')[0]);\n        $this-\u003eassertEquals($returnValue, $this-\u003egetSut()-\u003esign());\n    }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteffenbrand%2Fnon-static-php-jwt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsteffenbrand%2Fnon-static-php-jwt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteffenbrand%2Fnon-static-php-jwt/lists"}