Conditions | 5 |
Paths | 2 |
Total Lines | 29 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
40 | public function handle($request, \Closure $next) |
||
41 | { |
||
42 | // If we have add-on running locally we don't need to sign all requests with JWT token |
||
43 | // Of course you can provide it if you want. Otherwise request will be signed automatically |
||
44 | $jwt = request('jwt', request()->header('Authorization')); |
||
45 | |||
46 | if(app()->isLocal() && !$jwt) { |
||
|
|||
47 | if(!$tenant = $this->tenantService->dummy()) { |
||
48 | throw new \Illuminate\Validation\UnauthorizedException( |
||
49 | 'You should have at least one dummy tenant to get it working locally' |
||
50 | ); |
||
51 | } |
||
52 | |||
53 | $jwt = \AtlassianConnectCore\Helpers\JWTHelper::create( |
||
54 | $request->url(), |
||
55 | $request->method(), |
||
56 | $tenant->client_key, |
||
57 | $tenant->shared_secret |
||
58 | ); |
||
59 | |||
60 | $request->query->add(['jwt' => $jwt]); |
||
61 | } |
||
62 | |||
63 | // Authenticate user |
||
64 | if(!Auth::attempt()) { |
||
65 | throw new \Illuminate\Validation\UnauthorizedException(); |
||
66 | } |
||
67 | |||
68 | return $next($request); |
||
69 | } |
||
71 |