diff --git a/composer.json b/composer.json index db3d4aa..8055114 100644 --- a/composer.json +++ b/composer.json @@ -13,12 +13,12 @@ "designmynight" ], "require": { - "php": ">=7.2", - "laminas/laminas-diactoros": "^2.0", - "lcobucci/jwt": "3.3.3", - "illuminate/support": "^6.0 || ^7.0", - "jenssegers/mongodb": "3.6.* || 3.7.* || 4.0.* || 5.0.* || 6.0.*", - "laravel/passport": "^8.0 || ^9.0" + "php": ">=7.4", + "nyholm/psr7": "^1.0", + "lcobucci/jwt": "^4.0", + "illuminate/support": "^8.0", + "jenssegers/mongodb": "^3.8 || ^4.0", + "laravel/passport": "^10.0" }, "autoload": { "psr-4": { @@ -45,6 +45,6 @@ } }, "require-dev": { - "phpunit/phpunit": "^7.5" + "phpunit/phpunit": "^9.0" } } diff --git a/src/Passport/PersonalAccessTokenFactory.php b/src/Passport/PersonalAccessTokenFactory.php index e7a3c98..e9c458c 100644 --- a/src/Passport/PersonalAccessTokenFactory.php +++ b/src/Passport/PersonalAccessTokenFactory.php @@ -2,13 +2,16 @@ namespace DesignMyNight\Mongodb\Passport; -use Laminas\Diactoros\Response; -use Laminas\Diactoros\ServerRequest; -use Lcobucci\JWT\Parser as JwtParser; -use League\OAuth2\Server\AuthorizationServer; -use \Laravel\Passport\ClientRepository; +use Laravel\Passport\ClientRepository; +use Laravel\Passport\Passport; use Laravel\Passport\PersonalAccessTokenResult; use Laravel\Passport\TokenRepository; +use Lcobucci\JWT\Encoding\JoseEncoder; +use Lcobucci\JWT\Token\Parser; +use League\OAuth2\Server\AuthorizationServer; +use Nyholm\Psr7\Response; +use Nyholm\Psr7\ServerRequest; +use Psr\Http\Message\ServerRequestInterface; class PersonalAccessTokenFactory { @@ -36,7 +39,9 @@ class PersonalAccessTokenFactory /** * The JWT token parser instance. * - * @var \Lcobucci\JWT\Parser + * @var \Lcobucci\JWT\Token\Parser + * + * @deprecated This property will be removed in a future Passport version. */ protected $jwt; @@ -46,15 +51,16 @@ class PersonalAccessTokenFactory * @param \League\OAuth2\Server\AuthorizationServer $server * @param \Laravel\Passport\ClientRepository $clients * @param \Laravel\Passport\TokenRepository $tokens - * @param \Lcobucci\JWT\Parser $jwt + * @param \Lcobucci\JWT\Token\Parser|null $jwt * @return void */ - public function __construct(AuthorizationServer $server, - ClientRepository $clients, - TokenRepository $tokens, - JwtParser $jwt) - { - $this->jwt = $jwt; + public function __construct( + AuthorizationServer $server, + ClientRepository $clients, + TokenRepository $tokens, + $jwt = null + ) { + $this->jwt = $jwt ?? new Parser(new JoseEncoder()); $this->tokens = $tokens; $this->server = $server; $this->clients = $clients; @@ -92,14 +98,16 @@ public function make($userId, $name, array $scopes = []) * @param \Laravel\Passport\Client $client * @param mixed $userId * @param array $scopes - * @return \Laminas\Diactoros\ServerRequest + * @return \Psr\Http\Message\ServerRequestInterface */ protected function createRequest($client, $userId, array $scopes) { - return (new ServerRequest)->withParsedBody([ + $secret = Passport::$hashesClientSecrets ? $this->clients->getPersonalAccessClientSecret() : $client->secret; + + return (new ServerRequest('POST', ''))->withParsedBody([ 'grant_type' => 'personal_access', 'client_id' => $client->id, - 'client_secret' => $client->secret, + 'client_secret' => $secret, 'user_id' => $userId, 'scope' => implode(' ', $scopes), ]); @@ -108,13 +116,13 @@ protected function createRequest($client, $userId, array $scopes) /** * Dispatch the given request to the authorization server. * - * @param \Laminas\Diactoros\ServerRequest $request + * @param \Psr\Http\Message\ServerRequestInterface $request * @return array */ - protected function dispatchRequestToAuthorizationServer(ServerRequest $request) + protected function dispatchRequestToAuthorizationServer(ServerRequestInterface $request) { return json_decode($this->server->respondToAccessTokenRequest( - $request, new Response + $request, new Response() )->getBody()->__toString(), true); } @@ -127,7 +135,7 @@ protected function dispatchRequestToAuthorizationServer(ServerRequest $request) protected function findAccessToken(array $response) { return $this->tokens->find( - $this->jwt->parse($response['access_token'])->getClaim('jti') + $this->jwt->parse($response['access_token'])->claims()->get('jti') ); } }