o2system /
hydro
| 1 | <?php |
||||
| 2 | /** |
||||
| 3 | * This file is part of the O2System PHP Framework package. |
||||
| 4 | * |
||||
| 5 | * For the full copyright and license information, please view the LICENSE |
||||
| 6 | * file that was distributed with this source code. |
||||
| 7 | * |
||||
| 8 | * @author Steeve Andrian Salim |
||||
| 9 | * @copyright Copyright (c) Steeve Andrian Salim |
||||
| 10 | */ |
||||
| 11 | |||||
| 12 | // ------------------------------------------------------------------------ |
||||
| 13 | |||||
| 14 | namespace App\Http\Middleware; |
||||
| 15 | |||||
| 16 | // ------------------------------------------------------------------------ |
||||
| 17 | |||||
| 18 | use O2System\Psr\Http\Message\ServerRequestInterface; |
||||
| 19 | use O2System\Psr\Http\Server\RequestHandlerInterface; |
||||
| 20 | |||||
| 21 | /** |
||||
| 22 | * Class JsonWebToken |
||||
| 23 | * |
||||
| 24 | * @package O2System\Framework\Http\Middleware |
||||
| 25 | */ |
||||
| 26 | class JsonWebToken implements RequestHandlerInterface |
||||
| 27 | { |
||||
| 28 | /** |
||||
| 29 | * JsonWebToken::handle |
||||
| 30 | * |
||||
| 31 | * Handles a request and produces a response |
||||
| 32 | * |
||||
| 33 | * May call other collaborating code to generate the response. |
||||
| 34 | */ |
||||
| 35 | public function handle(ServerRequestInterface $request) |
||||
| 36 | { |
||||
| 37 | if (services()->has('jsonWebTokenAuthentication')) { |
||||
| 38 | /** |
||||
| 39 | * This is an example to implement HTTP Authentication with Json Web Token (JWT). |
||||
| 40 | * Try put this code into your request and see the result. |
||||
| 41 | * |
||||
| 42 | * eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjcsInVzZXJuYW1lIjoic3RlZXZlbnoifQ.D29MZcJa2svH5kNt4bFcUtIXvJ4ohYJ-0vNxsgMWAvc |
||||
| 43 | */ |
||||
| 44 | if(false !== ($token = input()->bearerToken())) { |
||||
|
0 ignored issues
–
show
introduced
by
Loading history...
The method
bearerToken() does not exist on O2System\Kernel\Cli\Input.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||
| 45 | $payload = services('jsonWebTokenAuthentication')->decode($token); |
||||
|
0 ignored issues
–
show
The method
decode() does not exist on O2System\Kernel\Containers\Services.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||
| 46 | globals()->store('payload', $payload); |
||||
| 47 | } else { |
||||
| 48 | output()->sendError(403, [ |
||||
| 49 | 'message' => language()->getLine('403_INVALID_JSONWEBTOKEN') |
||||
| 50 | ]); |
||||
| 51 | } |
||||
| 52 | } |
||||
| 53 | } |
||||
| 54 | } |