{"id":15739998,"url":"https://github.com/ace411/extjwt-cpp","last_synced_at":"2025-03-13T08:31:49.209Z","repository":{"id":112033007,"uuid":"162911076","full_name":"ace411/extjwt-cpp","owner":"ace411","description":"A simple PHP extension for encoding and decoding JSON Web Tokens (JWTs). ","archived":false,"fork":false,"pushed_at":"2020-03-09T17:31:46.000Z","size":60,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-26T19:27:23.962Z","etag":null,"topics":["extjwt-cpp","jwt","jwt-cpp","jwt-token","jwtauth","jwts","openssl","php","php-extension","php-jwt"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ace411.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":"2018-12-23T17:30:36.000Z","updated_at":"2024-07-11T13:38:10.000Z","dependencies_parsed_at":"2023-07-11T02:16:09.567Z","dependency_job_id":null,"html_url":"https://github.com/ace411/extjwt-cpp","commit_stats":{"total_commits":46,"total_committers":1,"mean_commits":46.0,"dds":0.0,"last_synced_commit":"76e2bdbea3594ebd439eff8bf192f2338c3c169e"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ace411%2Fextjwt-cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ace411%2Fextjwt-cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ace411%2Fextjwt-cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ace411%2Fextjwt-cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ace411","download_url":"https://codeload.github.com/ace411/extjwt-cpp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243369875,"owners_count":20280094,"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":["extjwt-cpp","jwt","jwt-cpp","jwt-token","jwtauth","jwts","openssl","php","php-extension","php-jwt"],"created_at":"2024-10-04T02:10:32.061Z","updated_at":"2025-03-13T08:31:49.142Z","avatar_url":"https://github.com/ace411.png","language":"C++","funding_links":["https://www.buymeacoffee.com/agiroLoki"],"categories":[],"sub_categories":[],"readme":"# extjwt-cpp\r\n\r\nA simple PHP extension for encoding and decoding JSON Web Tokens (JWTs). \r\n\r\n## Requirements\r\n\r\n- OpenSSL\r\n- [gtest](https://github.com/google/googletest) (for jwt-cpp)\r\n- [jwt-cpp](https://github.com/Thalhammer/jwt-cpp) package\r\n- PHP 7 or greater\r\n\r\n**Note:** Only POSIX Operating Systems are currently supported.\r\n\r\n## Supported Algorithms\r\n\r\n- HS256\r\n- HS384\r\n- HS512\r\n- RS256\r\n- RS384\r\n- RS512\r\n- PS256\r\n- PS384\r\n- PS512\r\n\r\n## Installation\r\n\r\nextjwt-cpp requires tools specified in the [precursory text](#requirements). Once said tools are successfully installed on your system, type the following in a console to install extjwt-cpp on your machine.\r\n\r\n```sh\r\ngit clone https://github.com/ace411/extjwt-cpp.git extjwt\r\ncd extjwt\r\nphpize\r\n./configure --enable-extjwt --with-jwtcpp=/path/to/jwtcpp --with-openssl=/path/to/openssl\r\nmake \u0026\u0026 sudo make install\r\n```\r\n\r\nIf you intend to run the tests in the tests directory, run the following command:\r\n\r\n```sh\r\nmake test\r\n```\r\n\r\n\u003e Do not forget to enable the extension by adding `extension=extjwt` to your `php.ini` file.\r\n\r\n## Usage\r\n\r\nShown below is an example of how to encode and decode a JWT using the default HS256 signature, a payload (claims), and a secret.\r\n\r\n```php\r\nconst SECRET = '@loki';\r\nconst CLAIMS = [\r\n    'iss'       =\u003e 'https://github.com/ace411/extjwt-cpp',\r\n    'aud'       =\u003e 'https://github.com/ace411/extjwt-cpp',\r\n    'user'      =\u003e [\r\n        'github'    =\u003e '@ace411',\r\n        'twitter'   =\u003e '@agiroLoki'\r\n    ],\r\n    'cpp_ver'   =\u003e 11\r\n];\r\n\r\n$token = jwt_encode(SECRET, CLAIMS); // outputs a string token\r\n\r\n$claims = jwt_decode($token, SECRET); // outputs a PHP hashtable\r\n```\r\n\r\n**The supported algorithm constants** are:\r\n\r\n- ```JWT_ALGO_HS256```\r\n- ```JWT_ALGO_HS384```\r\n- ```JWT_ALGO_HS512```\r\n- ```JWT_ALGO_RS256```\r\n- ```JWT_ALGO_RS384```\r\n- ```JWT_ALGO_RS512```\r\n- ```JWT_ALGO_PS256```\r\n- ```JWT_ALGO_PS384```\r\n- ```JWT_ALGO_PS512```\r\n\r\n## API\r\n\r\n- **`jwt_encode`**\r\n\r\n~~~\r\njwt_encode(string $secret, array $claims, int $algorithm)\r\n~~~\r\n\r\n**Description:** This function creates a JSON Web Token.\r\n\r\n**Since:**\r\n\r\n- v0.1.0\r\n\r\n**Argument(s):**\r\n\r\n- ***secret (string)*** - A discretionary secret key essential for JWT encipherment\r\n\u003e For algorithms prefixed with PS and RS, this is the private key\r\n\r\n- ***claims (array)*** - The JWT payload; a combination of registered, public, and private claims\r\n\r\n- ***algorithm (int)*** - The JWT signature algorithm\r\n\r\n**Usage:**\r\n\r\n~~~php\r\nconst RSA_PRIVATE_KEY = \u003c\u003c\u003c'KEY'\r\n-----BEGIN RSA PRIVATE KEY-----\r\nMIICXAIBAAKBgQC8kGa1pSjbSYZVebtTRBLxBz5H4i2p/llLCrEeQhta5kaQu/Rn\r\nvuER4W8oDH3+3iuIYW4VQAzyqFpwuzjkDI+17t5t0tyazyZ8JXw+KgXTxldMPEL9\r\n5+qVhgXvwtihXC1c5oGbRlEDvDF6Sa53rcFVsYJ4ehde/zUxo6UvS7UrBQIDAQAB\r\nAoGAb/MXV46XxCFRxNuB8LyAtmLDgi/xRnTAlMHjSACddwkyKem8//8eZtw9fzxz\r\nbWZ/1/doQOuHBGYZU8aDzzj59FZ78dyzNFoF91hbvZKkg+6wGyd/LrGVEB+Xre0J\r\nNil0GReM2AHDNZUYRv+HYJPIOrB0CRczLQsgFJ8K6aAD6F0CQQDzbpjYdx10qgK1\r\ncP59UHiHjPZYC0loEsk7s+hUmT3QHerAQJMZWC11Qrn2N+ybwwNblDKv+s5qgMQ5\r\n5tNoQ9IfAkEAxkyffU6ythpg/H0Ixe1I2rd0GbF05biIzO/i77Det3n4YsJVlDck\r\nZkcvY3SK2iRIL4c9yY6hlIhs+K9wXTtGWwJBAO9Dskl48mO7woPR9uD22jDpNSwe\r\nk90OMepTjzSvlhjbfuPN1IdhqvSJTDychRwn1kIJ7LQZgQ8fVz9OCFZ/6qMCQGOb\r\nqaGwHmUK6xzpUbbacnYrIM6nLSkXgOAwv7XXCojvY614ILTK3iXiLBOxPu5Eu13k\r\neUz9sHyD6vkgZzjtxXECQAkp4Xerf5TGfQXGXhxIX52yH+N2LtujCdkQZjXAsGdm\r\nB2zNzvrlgRmgBrklMTrMYgm1NPcW+bRLGcwgW2PTvNM=\r\n-----END RSA PRIVATE KEY-----\r\nKEY;\r\n\r\n$token = jwt_encode([\r\n    'user'      =\u003e 'ace411',\r\n    'twitter'   =\u003e '@agiroLoki',\r\n    'iss'       =\u003e 'example.org',\r\n    'aud'       =\u003e 'example.org',\r\n], RSA_PRIVATE_KEY, JWT_ALGO_RS256);\r\n\r\necho $token;\r\n~~~\r\n\r\n- **`jwt_decode`**\r\n\r\n~~~\r\njwt_decode(string $token, string $secret, int $algorithm)\r\n~~~\r\n\r\n**Description:** This function decodes a JSON Web Token into a list of claims.\r\n\r\n**Since:**\r\n\r\n- v0.1.0\r\n\r\n**Argument(s):**\r\n\r\n- ***token (string)*** - The JWT to decode\r\n\r\n- ***secret (string)*** - A discretionary secret key essential for JWT encipherment\r\n\u003e For algorithms prefixed with PS and RS, this is the public key\r\n\r\n- ***algorithm (int)*** - The JWT signature algorithm\r\n\r\n**Usage:**\r\n\r\n~~~php\r\n// combine with previous snippet\r\nconst RSA_PUBLIC_KEY = \u003c\u003c\u003c'KEY'\r\n-----BEGIN PUBLIC KEY-----\r\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8kGa1pSjbSYZVebtTRBLxBz5H\r\n4i2p/llLCrEeQhta5kaQu/RnvuER4W8oDH3+3iuIYW4VQAzyqFpwuzjkDI+17t5t\r\n0tyazyZ8JXw+KgXTxldMPEL95+qVhgXvwtihXC1c5oGbRlEDvDF6Sa53rcFVsYJ4\r\nehde/zUxo6UvS7UrBQIDAQAB\r\n-----END PUBLIC KEY-----\r\nKEY;\r\n\r\n$claims = jwt_decode($token, RSA_PUBLIC_KEY, JWT_ALGO_RS256);\r\n\r\nprint_r($claims);\r\n~~~\r\n\r\n## Why install extjwt-cpp?\r\n\r\nPHP extensions, are by virtue of being C/C++ syntaxes, faster than regular PHP. extjwt is a PHP module which wraps around another C++ library and infuses robustness into the PHP userland. Although it is possible to craft high-quality idiomatic PHP solutions like [php-jwt](https://github.com/firebase/php-jwt), extjwt is more performant.\r\n\r\n## Contributing\r\n\r\nConsider buying me a coffee if you appreciate the offerings of project.\r\n\r\n\u003ca href=\"https://www.buymeacoffee.com/agiroLoki\" target=\"_blank\"\u003e\u003cimg src=\"https://cdn.buymeacoffee.com/buttons/lato-white.png\" alt=\"Buy Me A Coffee\" style=\"height: 51px !important;width: 217px !important;\" \u003e\u003c/a\u003e\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Face411%2Fextjwt-cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Face411%2Fextjwt-cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Face411%2Fextjwt-cpp/lists"}