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 League\OAuth2\Server\AuthorizationServer; |
||
| 16 | use League\OAuth2\Server\Exception\OAuthServerException; |
||
| 17 | use League\OAuth2\Server\Grant\RefreshTokenGrant; |
||
| 18 | use OAuth2ServerExamples\Repositories\AccessTokenRepository; |
||
| 19 | use OAuth2ServerExamples\Repositories\ClientRepository; |
||
| 20 | use OAuth2ServerExamples\Repositories\RefreshTokenRepository; |
||
| 21 | use OAuth2ServerExamples\Repositories\ScopeRepository; |
||
| 22 | use Psr\Http\Message\ResponseInterface; |
||
| 23 | use Psr\Http\Message\ServerRequestInterface; |
||
| 24 | use Slim\App; |
||
|
0 ignored issues
–
show
|
|||
| 25 | |||
| 26 | $app = new App([ |
||
| 27 | 'settings' => [ |
||
| 28 | 'displayErrorDetails' => true, |
||
| 29 | ], |
||
| 30 | AuthorizationServer::class => function () { |
||
| 31 | // Init our repositories |
||
| 32 | $clientRepository = new ClientRepository(); |
||
| 33 | $accessTokenRepository = new AccessTokenRepository(); |
||
| 34 | $scopeRepository = new ScopeRepository(); |
||
| 35 | $refreshTokenRepository = new RefreshTokenRepository(); |
||
| 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 refresh token grant on the server |
||
| 49 | $grant = new RefreshTokenGrant($refreshTokenRepository); |
||
| 50 | $grant->setRefreshTokenTTL(new DateInterval('P1M')); // The refresh token will expire in 1 month |
||
| 51 | |||
| 52 | $server->enableGrantType( |
||
| 53 | $grant, |
||
| 54 | new DateInterval('PT1H') // The new access token will expire after 1 hour |
||
| 55 | ); |
||
| 56 | |||
| 57 | return $server; |
||
| 58 | }, |
||
| 59 | ]); |
||
| 60 | |||
| 61 | $app->post('/access_token', function (ServerRequestInterface $request, ResponseInterface $response) use ($app) { |
||
| 62 | /* @var \League\OAuth2\Server\AuthorizationServer $server */ |
||
| 63 | $server = $app->getContainer()->get(AuthorizationServer::class); |
||
| 64 | |||
| 65 | try { |
||
| 66 | return $server->respondToAccessTokenRequest($request, $response); |
||
| 67 | } catch (OAuthServerException $exception) { |
||
| 68 | return $exception->generateHttpResponse($response); |
||
| 69 | } catch (Exception $exception) { |
||
| 70 | $response->getBody()->write($exception->getMessage()); |
||
| 71 | |||
| 72 | return $response->withStatus(500); |
||
| 73 | } |
||
| 74 | }); |
||
| 75 | |||
| 76 | $app->run(); |
||
| 77 |
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