Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -45,6 +45,6 @@
}
},
"require-dev": {
"phpunit/phpunit": "^7.5"
"phpunit/phpunit": "^9.0"
}
}
48 changes: 28 additions & 20 deletions src/Passport/PersonalAccessTokenFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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),
]);
Expand All @@ -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);
}

Expand All @@ -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')
);
}
}