Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/ php-jwt Public
forked from cdoco/php-jwt

πŸ’§ A PHP extension for JSON Web Token

License

Notifications You must be signed in to change notification settings

feidou/php-jwt

Repository files navigation

A PHP extension for JSON Web Token (JWT)

Requirement

  • PHP 7 +
  • OpenSSL (Version >= 1.0.1f) Might work with older version as well, but I did not check that.

Install

$ git clone https://github.com/cdoco/php-jwt.git
$ cd php-jwt
$ phpize && ./configure --with-openssl=/path/to/openssl
$ make && make install

Quick Example

$key = "example_key";
$claims = array(
 "data" => [
 "name" => "ZiHang Gao",
 "admin" => true
 ],
 "iss" => "http://example.org",
 "sub" => "1234567890",
);
// default HS256 algorithm
$token = jwt_encode($claims, $key);
echo $token . PHP_EOL;
//eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.
//eyJpc3MiOiJodHRwOlwvXC9leGFtcGxlLm9yZyIsInN1YiI6IjEyMzQ1Njc4OTAiLCJuYW1lIjoiWmlIYW5nIEdhbyIsImFkbWluIjp0cnVlfQ.
//2lFeBTsRegsjXiBCZNkW41KFlsZPSFu7KTsyAM9lUiQ
print_r(jwt_decode($token, $key));
/**
Array
(
 [data] => Array
 (
 [name] => ZiHang Gao
 [admin] => 1
 )

 [iss] => http://example.org
 [sub] => 1234567890
)
*/

Benchmarks

Benchmarks

Methods

//encode
string jwt_encode(array $claims, string $key [, string $alg = 'HS256'])
//decode
array jwt_decode(string $token, string $key [, string $alg = 'HS256'])

The algorithm of support

algorithm - - -
HMAC HS256 HS384 HS512
RSA RS256 RS384 RS512
ECDSA ES256 ES384 ES512

License

PHP License. See the LICENSE file.

About

πŸ’§ A PHP extension for JSON Web Token

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 71.3%
  • PHP 22.7%
  • M4 3.9%
  • Shell 1.1%
  • JavaScript 1.0%

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /