php Jwt token 刷新

Controller.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
namespace App\Http\Controllers;
use Laravel\Lumen\Routing\Controller as BaseController;
use Tymon\JWTAuth\JWTAuth;
use Tymon\JWTAuth\Manager;

use Tymon\JWTAuth\Exceptions\TokenExpiredException;
use Tymon\JWTAuth\Exceptions\TokenBlacklistedException;

class Controller extends BaseController
{
/**
* @var JWTAuth
*/
protected $jwt;

/**
* @var Manager
*/
protected $manager;



/**
* Controller constructor.
*
* @param JWTAuth $jwt
* @param Manager $manager
*/
public function __construct(JWTAuth $jwt, Manager $manager)
{
$this->jwt = $jwt;
$this->manager = $manager;
}

refresh token

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/**
* 刷新token
* @param Request $request
* @return mixed
*/
public function refreshToken(Request $request){
try{
//get jwt token
$old_token = $this->jwt->getToken();
$token = $this->manager->refresh($old_token)->get();
}catch (TokenExpiredException $e){
return $this->json($e->getMessage(), 500);
}catch(JWTException $e){
return $this->json($e->getMessage(), 500);
}
return $this->json([
'token' => $token
]);
}
Reference
  1. how to refresh a token ? The token has been blacklisted ?