PHP code example of thans / tp-jwt-auth

1. Go to this page and download the library: Download thans/tp-jwt-auth library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

thans / tp-jwt-auth example snippets


 thans\jwt\middleware\JWTAuth::class,

use thans\jwt\facade\JWTAuth;

$token = JWTAuth::builder(['uid' => 1]);//参数为用户认证的信息,请自行添加

JWTAuth::auth();//token验证

JWTAuth::refresh();//刷新token,会将旧token加入黑名单

$tokenStr = JWTAuth::token()->get(); //可以获取请求中的完整token字符串

$payload = JWTAuth::auth(); //可验证token, 并获取token中的payload部分
$uid = $payload['uid']; //可以继而获取payload里自定义的字段,比如uid

shell
$ php think jwt:create