RefreshToken   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 3
c 3
b 1
f 0
lcom 1
cbo 4
dl 0
loc 27
ccs 0
cts 13
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 17 3
1
<?php
2
3
namespace Tymon\JWTAuth\Middleware;
4
5
use Tymon\JWTAuth\Exceptions\JWTException;
6
use Tymon\JWTAuth\Exceptions\TokenExpiredException;
7
8
class RefreshToken extends BaseMiddleware
9
{
10
    /**
11
     * Handle an incoming request.
12
     *
13
     * @param  \Illuminate\Http\Request  $request
14
     * @param  \Closure  $next
15
     * @return mixed
16
     */
17
    public function handle($request, \Closure $next, $custom =  [])
18
    {
19
        $response = $next($request);
20
21
        try {
22
            $newToken = $this->auth->setRequest($request)->parseToken()->refresh(false, $custom);
23
        } catch (TokenExpiredException $e) {
24
            return $this->respond('tymon.jwt.expired', 'token_expired', $e->getStatusCode(), [$e]);
25
        } catch (JWTException $e) {
26
            return $this->respond('tymon.jwt.invalid', 'token_invalid', $e->getStatusCode(), [$e]);
27
        }
28
29
        // send the refreshed token back to the client
30
        $response->headers->set('Authorization', 'Bearer ' . $newToken);
31
32
        return $response;
33
    }
34
}
35