{"id":23219122,"url":"https://github.com/b2pweb/jwt","last_synced_at":"2025-08-19T08:32:44.150Z","repository":{"id":185546812,"uuid":"673403834","full_name":"b2pweb/jwt","owner":"b2pweb","description":"Simple library for parse JWT token","archived":false,"fork":false,"pushed_at":"2025-06-17T13:22:40.000Z","size":39,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"1.1","last_synced_at":"2025-07-20T11:47:52.718Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/b2pweb.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-08-01T14:44:52.000Z","updated_at":"2025-06-17T13:22:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"3942d085-9892-495f-ba89-a84c5433aa9d","html_url":"https://github.com/b2pweb/jwt","commit_stats":null,"previous_names":["b2pweb/jwt"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/b2pweb/jwt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b2pweb%2Fjwt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b2pweb%2Fjwt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b2pweb%2Fjwt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b2pweb%2Fjwt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/b2pweb","download_url":"https://codeload.github.com/b2pweb/jwt/tar.gz/refs/heads/1.1","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b2pweb%2Fjwt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271121770,"owners_count":24702871,"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","status":"online","status_checked_at":"2025-08-19T02:00:09.176Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-12-18T21:19:20.852Z","updated_at":"2025-08-19T08:32:43.870Z","avatar_url":"https://github.com/b2pweb.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JWT\n[![build](https://github.com/b2pweb/jwt/actions/workflows/php.yml/badge.svg)](https://github.com/b2pweb/jwt/actions/workflows/php.yml)\n[![Packagist Version](https://img.shields.io/packagist/v/b2pweb/jwt.svg)](https://packagist.org/packages/b2pweb/jwt)\n[![Total Downloads](https://img.shields.io/packagist/dt/b2pweb/jwt.svg)](https://packagist.org/packages/b2pweb/jwt)\n[![Type Coverage](https://shepherd.dev/github/b2pweb/jwt/coverage.svg)](https://shepherd.dev/github/b2pweb/jwt)\n\nLibrary for parse and create JWT (JSON Web Token) in PHP, using [PHP JWT Framework](https://github.com/web-token/jwt-framework).\n\n## Installation\n\nInstall with composer :\n\n```bash\ncomposer require b2pweb/jwt\n```\n\n## Simple usage\n\n```php\n\u003c?php\n\n// Define algorithms\n$jwa = new \\B2pweb\\Jwt\\JWA();\n$jwa = $jwa-\u003efilter(['HS256', 'HS512', 'RS256', 'RS512']); // Filter enabled algorithms\n\n// Define your keys\n$jwks = new \\Jose\\Component\\Core\\JWKSet([\n    \\Jose\\Component\\KeyManagement\\JWKFactory::createFromKeyFile($privKey, null, ['use' =\u003e 'sig', 'kid' =\u003e 'key-user']),\n    // ...\n]);\n\n// Encode a payload to JWT\n$encoder = new \\B2pweb\\Jwt\\JwtEncoder($jwa);\n$jwt = $encoder-\u003eencode(\n    [\n        'iss' =\u003e 'https://example.com',\n        'aud' =\u003e 'https://example.com',\n        'iat' =\u003e time(),\n        'exp' =\u003e time() + 3600,\n        'sub' =\u003e '1234567890',\n        'name' =\u003e 'John Doe',\n        'admin' =\u003e true,\n    ],\n    // You can configure encoding options here, like the key to use, the algorithm, ...\n    (new \\B2pweb\\Jwt\\EncodingOptions($jwks))\n        -\u003esetAlgorithm('RS512')\n        -\u003esetKid('key-user')\n);\n\n// You can also use an object that implements \\B2pweb\\Jwt\\ClaimsInterface\n// allowing you to customize the claims serialization to JSON\n// If you extends \\B2pweb\\Jwt\\Claims, you can define Claims::$encodingFlags on the subclass to customize the JSON encoding flags\n$claims = new \\B2pweb\\Jwt\\Claims([\n    'iss' =\u003e 'https://example.com',\n    'aud' =\u003e 'https://example.com',\n    'iat' =\u003e time(),\n    'exp' =\u003e time() + 3600,\n    'sub' =\u003e '1234567890',\n    'name' =\u003e 'John Doe',\n    'admin' =\u003e true,\n]);\n$jwt = $encoder-\u003eencode(\n    $claims,\n    // You can use EncodingOptions::fromKey, which will automatically set the algorithm and the kid from the given key\n    \\B2pweb\\Jwt\\EncodingOptions::fromKey(\\Jose\\Component\\KeyManagement\\JWKFactory::createFromSecret($secret, ['use' =\u003e 'sig', 'alg' =\u003e 'HS256']))\n);\n\n// Decode a JWT\n$decoder = new \\B2pweb\\Jwt\\JwtDecoder($jwa);\n\n$token = $decoder-\u003edecode($jwt, $jwks); // Return a \\B2pweb\\Jwt\\Claims object\n$token-\u003eclaim('iss'); // Return 'https://example.com'\n\n// Yan can also define allowed algorithms using JwtDecoder::supportedAlgorithms()\n$token = $decoder-\u003esupportedAlgorithms(['RS256', 'RS512'])-\u003edecode($jwt, $jwks);\n\n// You can also decode a JWT without verifying the signature\n$token = \\B2pweb\\Jwt\\JWT::fromJwtUnsafe($jwt);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fb2pweb%2Fjwt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fb2pweb%2Fjwt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fb2pweb%2Fjwt/lists"}