tokin/json-web-tokin
最新稳定版本:1.0
Composer 安装命令:
composer require tokin/json-web-tokin
包简介
A JSON Web Token Library
README 文档
README
Tokin some webs
Description:
This is small library that can be used to verify JSON Web Tokens. There are 2 classes that are
used in this library JsonWebToken and Verifier, the JsonWebToken class allows to segment the pieces
of the token out so they can be easily generated/derived.
To use the Verifier, all you will need is a JsonWebToken instance, as well as the key that was used to sign
token (in a lot of cases this will be your Client Secret).
Examples
Verifying a JWT
use Tokin\JWT\JsonWebToken; use Tokin\JWT\Verifier; $token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjEyMzM0NjQ2NCIsImZpcnN0X25hbWUiOiJUZXN0IiwibGFzdF9uYW1lIjoiTWNUZXN0ZXJzb24iLCJlbWFpbCI6InRlc3RAdGVzdC5jb20iLCJleHBpcmVzIjoxMjMyMTQyfQ.7BHgbsBAyK0IRDKPtFOhHKFYta6_fdujngX64zMYrtg'; $key = 'abcdefghijklmno'; $verifier = new Verifier(); $jwt = new JsonWebToken($token); return $verifier->verify($jwt, $key); // returns a boolean
Retrieving Header Info From JWT
use Tokin\JWT\JsonWebToken; $token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjEyMzM0NjQ2NCIsImZpcnN0X25hbWUiOiJUZXN0IiwibGFzdF9uYW1lIjoiTWNUZXN0ZXJzb24iLCJlbWFpbCI6InRlc3RAdGVzdC5jb20iLCJleHBpcmVzIjoxMjMyMTQyfQ.7BHgbsBAyK0IRDKPtFOhHKFYta6_fdujngX64zMYrtg'; $jwt = new JsonWebToken($token); $headers = $jwt->getHeader(true); // this will return the JSON for the header, false will return the Base 64 URL Encoded value // {"typ": "JWT", "alg":"HS256"}
Retrieving the Payload Info From JWT
use Tokin\JWT\JsonWebToken; $token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjEyMzM0NjQ2NCIsImZpcnN0X25hbWUiOiJUZXN0IiwibGFzdF9uYW1lIjoiTWNUZXN0ZXJzb24iLCJlbWFpbCI6InRlc3RAdGVzdC5jb20iLCJleHBpcmVzIjoxMjMyMTQyfQ.7BHgbsBAyK0IRDKPtFOhHKFYta6_fdujngX64zMYrtg'; $jwt = new JsonWebToken($token); $payload = $jwt->getPayload(true); // this will return the JSON for the header, false will return the Base 64 URL Encoded value
Retrieving the Signature From JWT
use Tokin\JWT\JsonWebToken; $token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjEyMzM0NjQ2NCIsImZpcnN0X25hbWUiOiJUZXN0IiwibGFzdF9uYW1lIjoiTWNUZXN0ZXJzb24iLCJlbWFpbCI6InRlc3RAdGVzdC5jb20iLCJleHBpcmVzIjoxMjMyMTQyfQ.7BHgbsBAyK0IRDKPtFOhHKFYta6_fdujngX64zMYrtg'; $jwt = new JsonWebToken($token); $signature = $jwt->getSignature();
Retrieving the Original JWT
use Tokin\JWT\JsonWebToken; $token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjEyMzM0NjQ2NCIsImZpcnN0X25hbWUiOiJUZXN0IiwibGFzdF9uYW1lIjoiTWNUZXN0ZXJzb24iLCJlbWFpbCI6InRlc3RAdGVzdC5jb20iLCJleHBpcmVzIjoxMjMyMTQyfQ.7BHgbsBAyK0IRDKPtFOhHKFYta6_fdujngX64zMYrtg'; $jwt = new JsonWebToken($token); $token = $jwt->getOriginalToken();
统计信息
- 总下载量: 2.34k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-02-11