matiasnamendola / slimpower-jwt
一个简单的PHP库,用于编码和解码JSON Web Tokens (JWT),符合RFC 7519规范
v0.0.1-alpha
2016-12-07 02:33 UTC
Requires
- php: >=5.3.0
- symfony/yaml: v2.6.0
This package is not auto-updated.
Last update: 2024-09-28 20:20:05 UTC
README
一个简单的PHP库,用于编码和解码JSON Web Tokens (JWT),符合RFC 7519规范。
安装
在终端中,使用composer管理依赖并下载'Slimpower JWT'
composer require matiasnamendola/slimpower-jwt
或者您可以在您的composer.json中添加以下内容
{ "require": { "matiasnamendola/slimpower-jwt": "dev-master" } }
示例
<?php use \SlimPower\JWT\JWT; $key = "secret"; $token = array( "iss" => "http://example.org", "aud" => "http://example.com", "iat" => 1481113105, "nbf" => 1481000000 ); /** * IMPORTANT: * You must specify supported algorithms for your application. See * https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40 * for a list of spec-compliant algorithms. */ $jwt = JWT::encode($token, $key); $decoded = JWT::decode($jwt, $key, array('HS256')); print_r($decoded); /* NOTE: This will now be an object instead of an associative array. To get an associative array, you will need to cast it as such: */ $decoded_array = (array) $decoded; /** * You can add a leeway to account for when there is a clock skew times between * the signing and verifying servers. It is recommended that this leeway should * not be bigger than a few minutes. * * Source: http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html#nbfDef */ JWT::$leeway = 60; // $leeway in seconds $decoded = JWT::decode($jwt, $key, array('HS256')); ?>
致谢
许可协议
MIT许可(MIT)。请参阅许可文件以获取更多信息。