thephpleague /
oauth2-server
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * @author Alex Bilbie <[email protected]> |
||
| 5 | * @copyright Copyright (c) Alex Bilbie |
||
| 6 | * @license http://mit-license.org/ |
||
| 7 | * |
||
| 8 | * @link https://github.com/thephpleague/oauth2-server |
||
| 9 | */ |
||
| 10 | |||
| 11 | declare(strict_types=1); |
||
| 12 | |||
| 13 | include __DIR__ . '/../vendor/autoload.php'; |
||
| 14 | |||
| 15 | use Laminas\Diactoros\Stream; |
||
| 16 | use League\OAuth2\Server\AuthorizationServer; |
||
| 17 | use League\OAuth2\Server\Exception\OAuthServerException; |
||
| 18 | use League\OAuth2\Server\Grant\ImplicitGrant; |
||
| 19 | use OAuth2ServerExamples\Entities\UserEntity; |
||
| 20 | use OAuth2ServerExamples\Repositories\AccessTokenRepository; |
||
| 21 | use OAuth2ServerExamples\Repositories\ClientRepository; |
||
| 22 | use OAuth2ServerExamples\Repositories\ScopeRepository; |
||
| 23 | use Psr\Http\Message\ResponseInterface; |
||
| 24 | use Psr\Http\Message\ServerRequestInterface; |
||
| 25 | use Slim\App; |
||
|
0 ignored issues
–
show
|
|||
| 26 | |||
| 27 | $app = new App([ |
||
| 28 | 'settings' => [ |
||
| 29 | 'displayErrorDetails' => true, |
||
| 30 | ], |
||
| 31 | AuthorizationServer::class => function () { |
||
| 32 | // Init our repositories |
||
| 33 | $clientRepository = new ClientRepository(); |
||
| 34 | $scopeRepository = new ScopeRepository(); |
||
| 35 | $accessTokenRepository = new AccessTokenRepository(); |
||
| 36 | |||
| 37 | $privateKeyPath = 'file://' . __DIR__ . '/../private.key'; |
||
| 38 | |||
| 39 | // Setup the authorization server |
||
| 40 | $server = new AuthorizationServer( |
||
| 41 | $clientRepository, |
||
| 42 | $accessTokenRepository, |
||
| 43 | $scopeRepository, |
||
| 44 | $privateKeyPath, |
||
| 45 | 'lxZFUEsBCJ2Yb14IF2ygAHI5N4+ZAUXXaSeeJm6+twsUmIen' |
||
| 46 | ); |
||
| 47 | |||
| 48 | // Enable the implicit grant on the server with a token TTL of 1 hour |
||
| 49 | $server->enableGrantType(new ImplicitGrant(new DateInterval('PT1H'))); |
||
| 50 | |||
| 51 | return $server; |
||
| 52 | }, |
||
| 53 | ]); |
||
| 54 | |||
| 55 | $app->get('/authorize', function (ServerRequestInterface $request, ResponseInterface $response) use ($app) { |
||
| 56 | /* @var \League\OAuth2\Server\AuthorizationServer $server */ |
||
| 57 | $server = $app->getContainer()->get(AuthorizationServer::class); |
||
| 58 | |||
| 59 | try { |
||
| 60 | // Validate the HTTP request and return an AuthorizationRequest object. |
||
| 61 | // The auth request object can be serialized into a user's session |
||
| 62 | $authRequest = $server->validateAuthorizationRequest($request); |
||
| 63 | |||
| 64 | // Once the user has logged in set the user on the AuthorizationRequest |
||
| 65 | $authRequest->setUser(new UserEntity()); |
||
| 66 | |||
| 67 | // Once the user has approved or denied the client update the status |
||
| 68 | // (true = approved, false = denied) |
||
| 69 | $authRequest->setAuthorizationApproved(true); |
||
| 70 | |||
| 71 | // Return the HTTP redirect response |
||
| 72 | return $server->completeAuthorizationRequest($authRequest, $response); |
||
| 73 | } catch (OAuthServerException $exception) { |
||
| 74 | return $exception->generateHttpResponse($response); |
||
| 75 | } catch (Exception $exception) { |
||
| 76 | $body = new Stream('php://temp', 'r+'); |
||
| 77 | $body->write($exception->getMessage()); |
||
| 78 | |||
| 79 | return $response->withStatus(500)->withBody($body); |
||
| 80 | } |
||
| 81 | }); |
||
| 82 | |||
| 83 | $app->run(); |
||
| 84 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths