{"id":37003987,"url":"https://github.com/ngphp/jwt","last_synced_at":"2026-01-14T00:36:11.522Z","repository":{"id":244229174,"uuid":"814651501","full_name":"ngphp/jwt","owner":"ngphp","description":"NGPHP/JWT is a simple library to encode and decode JSON Web Tokens (JWT) in PHP. This library is part of the LeanPHP framework and was developed by Vedat Yıldırım. It provides methods to generate, validate, and decode JWT tokens, conforming to the current specifications.","archived":false,"fork":false,"pushed_at":"2024-06-13T13:39:42.000Z","size":18,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-20T05:03:17.587Z","etag":null,"topics":["jwt","jwt-auth","jwt-authentication","jwt-token"],"latest_commit_sha":null,"homepage":"https://ngphp.com","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/ngphp.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}},"created_at":"2024-06-13T12:30:19.000Z","updated_at":"2024-06-13T13:37:12.000Z","dependencies_parsed_at":"2024-06-13T14:41:42.081Z","dependency_job_id":"708505e1-c1c5-498d-ac85-6df12059c35e","html_url":"https://github.com/ngphp/jwt","commit_stats":null,"previous_names":["ngphp/jwt"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ngphp/jwt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngphp%2Fjwt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngphp%2Fjwt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngphp%2Fjwt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngphp%2Fjwt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ngphp","download_url":"https://codeload.github.com/ngphp/jwt/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngphp%2Fjwt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28406520,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["jwt","jwt-auth","jwt-authentication","jwt-token"],"created_at":"2026-01-14T00:36:10.623Z","updated_at":"2026-01-14T00:36:11.427Z","avatar_url":"https://github.com/ngphp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JWT\nNGPHP/JWT is a simple library to encode and decode JSON Web Tokens (JWT) in PHP. \nThis library is part of the NGPHP framework and was developed by Vedat Yıldırım. \nIt provides methods to generate, validate, and decode JWT tokens, conforming to the current specifications. \n\n## Installation\n\nYou can install this package via Composer: https://packagist.org/packages/ngphp/jwt\n\n```bash\ncomposer install ngphp/jwt\n```\n\n## Example\n\nfile: vendor/ngphp/src/example.php\nurl: http://localhost/jwt/example.php\n\n\n## Usage\n\n### Generating a JWT\n\n```\n// without composer: require 'JWT.php';\n\n// with composer\nrequire 'vendor/autoload.php';\n\nuse ngphp\\JWT;\n\n// Initialize the JWT handler with a secret key\n$secret = 'your_secret_key';\n$jwt = new JWT($secret);\n\n// Example payload\n$payload = [\n    'user_id' =\u003e 1,\n    'username' =\u003e 'john.doe',\n    'email' =\u003e 'john.doe@example.com',\n    'role' =\u003e 'admin',\n    'iat' =\u003e time(),\n    'exp' =\u003e time() + 3600 // 1 hour expiration\n];\n\n// Generate a JWT\n$token = $jwt-\u003egenerate($payload);\necho \"Generated Token: \" . $token . \"\\n\";\n```\n\n### Authenticating a JWT\n\n```\n// Example headers containing the JWT\n$headers = [\n    'Authorization' =\u003e 'Bearer ' . $token\n];\n\n// Authenticate the user using the token from the headers\ntry {\n    if ($jwt-\u003eauthenticate($headers)) {\n        $user = JWT::getUser();\n        echo \"Authenticated User: \\n\";\n        print_r($user);\n    }\n} catch (\\Exception $e) {\n    echo \"Authentication failed: \" . $e-\u003egetMessage() . \"\\n\";\n}\n\n```\n\n### Decoding a JWT\n\n```\n// Decode the token directly\ntry {\n    $decoded = $jwt-\u003edecode($token);\n    echo \"Decoded Token: \\n\";\n    print_r($decoded);\n} catch (\\Exception $e) {\n    echo \"Decoding failed: \" . $e-\u003egetMessage() . \"\\n\";\n}\n```\n\n### Example\n\nHere's a more detailed example that demonstrates generating, storing, authenticating, and decoding a JWT.\n\n```\nrequire 'vendor/autoload.php';\n\nuse leanphp\\jwt\\JWT;\n\n// Initialize the JWT handler with a secret key\n$secret = 'your_secret_key';\n$jwt = new JWT($secret);\n\n// Example payload\n$payload = [\n    'user_id' =\u003e 1,\n    'username' =\u003e 'john.doe',\n    'email' =\u003e 'john.doe@example.com',\n    'role' =\u003e 'admin',\n    'iat' =\u003e time(),\n    'exp' =\u003e time() + 3600 // 1 hour expiration\n];\n\n// Generate a JWT\n$token = $jwt-\u003egenerate($payload);\necho \"Generated Token: \" . $token . \"\\n\\n\";\n\n// Simulate storing the token in a database\necho \"Storing the token in the database...\\n\\n\";\n// Example of database storage logic (not implemented here)\n// storeTokenInDatabase($user_id, $token);\n\n// Example headers containing the JWT\n$headers = [\n    'Authorization' =\u003e 'Bearer ' . $token\n];\n\n// Authenticate the user using the token from the headers\necho \"Authenticating User...\\n\";\ntry {\n    if ($jwt-\u003eauthenticate($headers)) {\n        $user = JWT::getUser();\n        echo \"Authenticated User: \\n\";\n        print_r($user);\n        echo \"\\n\";\n    }\n} catch (\\Exception $e) {\n    echo \"Authentication failed: \" . $e-\u003egetMessage() . \"\\n\";\n}\n\n// Decode the token directly\necho \"Decoding the Token...\\n\";\ntry {\n    $decoded = $jwt-\u003edecode($token);\n    echo \"Decoded Token: \\n\";\n    print_r($decoded);\n    echo \"\\n\";\n} catch (\\Exception $e) {\n    echo \"Decoding failed: \" . $e-\u003egetMessage() . \"\\n\";\n}\n\n// Example output separation\necho \"\\n--------------------------\\n\";\necho \"Example 1: Token Generation\\n\";\necho \"Generated Token: \" . $token . \"\\n\";\n\necho \"\\n--------------------------\\n\";\necho \"Example 2: Token Authentication\\n\";\ntry {\n    if ($jwt-\u003eauthenticate($headers)) {\n        $user = JWT::getUser();\n        echo \"Authenticated User: \\n\";\n        print_r($user);\n        echo \"\\n\";\n    }\n} catch (\\Exception $e) {\n    echo \"Authentication failed: \" . $e-\u003egetMessage() . \"\\n\";\n}\n\necho \"\\n--------------------------\\n\";\necho \"Example 3: Token Decoding\\n\";\ntry {\n    $decoded = $jwt-\u003edecode($token);\n    echo \"Decoded Token: \\n\";\n    print_r($decoded);\n    echo \"\\n\";\n} catch (\\Exception $e) {\n    echo \"Decoding failed: \" . $e-\u003egetMessage() . \"\\n\";\n}\n\n```\n\nLicense\nThis project is licensed under the MIT License. See the LICENSE file for more details.\n\nAcknowledgements\nThis library is part of the LeanPHP framework and was developed by Vedat Yıldırım.\n\nContributing\nIf you find any issues or have suggestions for improvements, feel free to open an issue or submit a pull request on GitHub.\n\n\nThis `README.md` provides an overview of the JWT library, including installation instructions, usage examples, and detailed explanations of each method. It also includes a complete example demonstrating how to generate, authenticate, and decode JWT tokens. The repository name `php-jwt` is concise and SEO-friendly, making it easier for users to find your project when searching for JWT solutions in PHP.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fngphp%2Fjwt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fngphp%2Fjwt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fngphp%2Fjwt/lists"}