Conditions | 4 |
Paths | 10 |
Total Lines | 22 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 20 |
Changes | 0 |
1 | <?php |
||
32 | public function handle(Request $request, Closure $next) |
||
33 | { |
||
34 | $auth0 = \App::make('auth0'); |
||
35 | |||
36 | $accessToken = $request->bearerToken(); |
||
37 | |||
38 | try { |
||
39 | $tokenInfo = $auth0->decodeJWT($accessToken); |
||
40 | $user = $this->auth0Service->getUserByDecodedJWT($tokenInfo); |
||
41 | |||
42 | if (! $user) { |
||
|
|||
43 | return response()->json(['error' => 'Unauthorized user.'], 401); |
||
44 | } |
||
45 | |||
46 | \Auth::login($user); |
||
47 | } catch (InvalidTokenException $e) { |
||
48 | return response()->json(['error' => 'Invalid or no token set.'], 401); |
||
49 | } catch (CoreException $e) { |
||
50 | return response()->json(['error' => $e->getMessage()], 401); |
||
51 | } |
||
52 | |||
53 | return $next($request); |
||
54 | } |
||
56 |