{"id":16387591,"url":"https://github.com/bitnbytesio/jwt","last_synced_at":"2025-10-26T11:31:52.253Z","repository":{"id":62488077,"uuid":"139761824","full_name":"bitnbytesio/jwt","owner":"bitnbytesio","description":"PHP7 library for JSON Web Tokens (JWT)","archived":false,"fork":false,"pushed_at":"2018-07-05T15:30:12.000Z","size":8,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-31T19:01:39.362Z","etag":null,"topics":["jwt","laravel","php","php7"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bitnbytesio.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-04T20:01:35.000Z","updated_at":"2024-12-19T11:59:10.000Z","dependencies_parsed_at":"2022-11-02T10:47:06.429Z","dependency_job_id":null,"html_url":"https://github.com/bitnbytesio/jwt","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitnbytesio%2Fjwt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitnbytesio%2Fjwt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitnbytesio%2Fjwt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitnbytesio%2Fjwt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bitnbytesio","download_url":"https://codeload.github.com/bitnbytesio/jwt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238319532,"owners_count":19452353,"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","laravel","php","php7"],"created_at":"2024-10-11T04:26:56.135Z","updated_at":"2025-10-26T11:31:46.959Z","avatar_url":"https://github.com/bitnbytesio.png","language":"PHP","funding_links":[],"categories":["库和框架"],"sub_categories":["PHP"],"readme":"PHP-JWT\n=======\n\nPHP7 library for JSON Web Tokens (JWT).\n\n[Standard]https://en.wikipedia.org/wiki/JSON_Web_Token#Standard_fields\n\nInstallation\n------------\n\n```sh\ncomposer require artisangang/jwt\n```\n\nRequires PHP 7.\n\nUsage\n-----\n\n```php\n\u003c?php\n\n\n// create token\n\n$token = Token::make([\n    \t'key' =\u003e 'secret',\n    \t'issuer' =\u003e 'artisangang',\n    \t'expiry' =\u003e strtotime('+1 hour'),\n    \t'issuedAt' =\u003e time(),\n    \t'algorithm' =\u003e 'HS256'\n    ])-\u003eget();\n\n\ntry {\n\tToken::validate($token, 'secret');\n} catch (\\Exception $e) {\n\t//InvalidArgumentException|UnexpectedValueException\n\t//InvalidSignatureException|BeforeValidException|TokenExpiredException\n}\n\n/**\n * or\n * Token::check($token, 'secret')\n * this will return true or false only\n */\n\n//  decode token\n// (new Token)-\u003edecode('token', 'key')\n\n// token string to token object\n// Token::break('token', 'key')\n\n// jwt claims maping with Token Class\n/**\n * [\n *    'iss' =\u003e 'issuer',\n *    'sub' =\u003e 'subject',\n *    'aud' =\u003e 'audience',\n *    'exp' =\u003e 'expiry',\n *    'nbf' =\u003e 'notBefore',\n *    'iat' =\u003e 'issuedAt',\n *    'jti' =\u003e 'identify',\n *    'typ' =\u003e 'type',\n *    'alg' =\u003e 'algorithm'\n *]\n */\n\n```\n\n\nUsing methods\n\n```php\n\n$token = new Token;\n\n$token-\u003esetKey('secret);\n\n$token-\u003esetIssuer('who issued this token');\n\n$token-\u003esetSubject('subject of token');\n\n$token-\u003esetAudience('recipients');\n\n// of in case of multiple audience\n//$token-\u003esetAudience('recipient1', 'recipient2', 'recipient3');\n\n// this will work with unix timestamp\n$token-\u003esetExpiry(time() + 60);\n\n// this token cannot be used before\n$token-\u003esetNotBefore(time() + 10);\n\n// token issued at unix time stamp\n// Note: token cannot be used before issued at time\n$token-\u003esetIssuedAt(time());\n\n$token-\u003esetIdentity('this must be unique');\n\n$token-\u003esetType('jwt');\n\n// suported algorithm: HS256,HS512,HS384\n// for oppen ssl : RS256,RS384,RS512 \n$token-\u003esetAlgorithm('HS256');\n\n// add custom claims to token\n$token-\u003esetClaim('user_id', 1);\n$token-\u003esetClaim('email', 'user@example.com');\n\n// generate token based on claims\n$tokenString = $token-\u003eget();\n\n\n\n```\n\nValidating a token\n\n```php\n\n// use one from below methods\n\ntry {\n    \n    // this will return array of claims\n    $token = Token::validate('token string', 'your key');\n    \n    // you may validate custom claims here\n    \n   } catch(\\Exception $e) \n   {\n        //InvalidArgumentException -\u003e some required argument is missing\n        //UnexpectedValueException -\u003e argument or segment value is malformed\n        //InvalidSignatureException -\u003e token signature not matched , Token is invalid\n        //BeforeValidException -\u003e token is used before issued at or not before time\n        //TokenExpiredException -\u003e token is expired\n   }\n   \n// or by using check, this will return bool\n\nif (!Token::check('token string', 'your key'))\n{\n    // token is not valid\n}\n\n```\n\nFor more information explorer JWT\\Token.php.\n\nUse openssl_pkcs12_read,openssl_get_privatekey to read key.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitnbytesio%2Fjwt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitnbytesio%2Fjwt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitnbytesio%2Fjwt/lists"}