Skip to content

Commit 1be3792

Browse files
author
Cor Bosman
committed
add passport 13 support
1 parent 523617d commit 1be3792

5 files changed

Lines changed: 26 additions & 19 deletions

File tree

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
],
1919
"require": {
2020
"illuminate/support": "^11.0|^12.0",
21-
"laravel/passport": "^11.2|^12.0",
21+
"laravel/passport": "^11.2|^12.0|^13.0",
2222
"nesbot/carbon": "^3"
2323
},
2424
"require-dev": {
@@ -49,7 +49,8 @@
4949
"config": {
5050
"allow-plugins": {
5151
"phpstan/extension-installer": true,
52-
"pestphp/pest-plugin": true
52+
"pestphp/pest-plugin": true,
53+
"php-http/discovery": true
5354
}
5455
}
5556
}

src/AccessToken.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,9 @@ private function convertToJWT() : Token
4343
->reduce(fn($jwt, $value, $key) => $jwt->withClaim($key, $value), $jwt)
4444
->getToken($this->jwtConfiguration->signer(), $this->jwtConfiguration->signingKey());
4545
}
46+
47+
public function __toString()
48+
{
49+
return $this->convertToJWT()->toString();
50+
}
4651
}

src/AccessTokenRepository.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace CorBosman\Passport;
44

5+
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
56
use League\OAuth2\Server\Entities\ClientEntityInterface;
67
use Laravel\Passport\Bridge\AccessTokenRepository as PassportAccessTokenRepository;
78

@@ -10,7 +11,7 @@ class AccessTokenRepository extends PassportAccessTokenRepository
1011
/**
1112
* {@inheritdoc}
1213
*/
13-
public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, $userIdentifier = null)
14+
public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, ?string $userIdentifier = null): AccessTokenEntityInterface
1415
{
1516
return new AccessToken($userIdentifier, $scopes, $clientEntity);
1617
}

tests/AccessTokenClaimTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ protected function tearDown(): void
2929
public function test_can_add_claims_to_token()
3030
{
3131
/* set up the environment */
32-
$repository = new AccessTokenRepository(m::mock(TokenRepository::class), m::mock(Dispatcher::class));
33-
$client = new Client('client-id', 'name', 'redirect');
32+
$repository = new AccessTokenRepository(m::mock(Dispatcher::class));
33+
$client = new Client('client-id', 'name', ['redirect']);
3434
$scopes = [];
3535
$userIdentifier = 1;
3636
$keys = (new RSA())->createKey(2048);
@@ -55,8 +55,8 @@ public function test_can_add_claims_to_token()
5555
public function test_jwt_dose_not_include_iss_claim_by_default()
5656
{
5757
/* set up the environment */
58-
$repository = new AccessTokenRepository(m::mock(TokenRepository::class), m::mock(Dispatcher::class));
59-
$client = new Client('client-id', 'name', 'redirect');
58+
$repository = new AccessTokenRepository(m::mock(Dispatcher::class));
59+
$client = new Client('client-id', 'name', ['redirect']);
6060
$scopes = [];
6161
$userIdentifier = 1;
6262
$keys = (new RSA())->createKey(2048);
@@ -77,8 +77,8 @@ public function test_jwt_dose_not_include_iss_claim_by_default()
7777
public function test_jwt_has_iss_claim_when_configured()
7878
{
7979
/* set up the environment */
80-
$repository = new AccessTokenRepository(m::mock(TokenRepository::class), m::mock(Dispatcher::class));
81-
$client = new Client('client-id', 'name', 'redirect');
80+
$repository = new AccessTokenRepository(m::mock(Dispatcher::class));
81+
$client = new Client('client-id', 'name', ['redirect']);
8282
$scopes = [];
8383
$userIdentifier = 1;
8484
$keys = (new RSA())->createKey(2048);

tests/CheckClaimMiddlewareTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ protected function tearDown(): void
2929
public function test_request_is_passed_along_if_claim_is_present_on_token()
3030
{
3131
/* set up token with custom claim */
32-
$repository = new AccessTokenRepository(m::mock(TokenRepository::class), m::mock(Dispatcher::class));
33-
$client = new Client('client-id', 'name', 'redirect');
32+
$repository = new AccessTokenRepository(m::mock(Dispatcher::class));
33+
$client = new Client('client-id', 'name', ['redirect']);
3434
$keys = (new RSA())->createKey(2048);
3535
app('config')->set('passport-claims.claims', [MyClaim::class]);
3636
$token = $repository->getNewToken($client, [], '');
@@ -54,8 +54,8 @@ public function test_request_is_passed_along_if_claim_is_present_on_token()
5454
public function test_request_is_passed_along_if_claim_matches_a_value()
5555
{
5656
/* set up token with custom claim */
57-
$repository = new AccessTokenRepository(m::mock(TokenRepository::class), m::mock(Dispatcher::class));
58-
$client = new Client('client-id', 'name', 'redirect');
57+
$repository = new AccessTokenRepository(m::mock(Dispatcher::class));
58+
$client = new Client('client-id', 'name', ['redirect']);
5959
$keys = (new RSA())->createKey(2048);
6060
app('config')->set('passport-claims.claims', [MyClaim::class]);
6161
$token = $repository->getNewToken($client, [], '');
@@ -79,8 +79,8 @@ public function test_request_is_passed_along_if_claim_matches_a_value()
7979
public function test_request_is_passed_along_if_claim_matches_a_value_from_many()
8080
{
8181
/* set up token with custom claim */
82-
$repository = new AccessTokenRepository(m::mock(TokenRepository::class), m::mock(Dispatcher::class));
83-
$client = new Client('client-id', 'name', 'redirect');
82+
$repository = new AccessTokenRepository(m::mock(Dispatcher::class));
83+
$client = new Client('client-id', 'name', ['redirect']);
8484
$keys = (new RSA())->createKey(2048);
8585
app('config')->set('passport-claims.claims', [MyClaim::class]);
8686
$token = $repository->getNewToken($client, [], '');
@@ -106,8 +106,8 @@ public function test_exception_is_thrown_if_token_doesnt_have_claim()
106106
$this->expectException(AuthenticationException::class);
107107

108108
/* set up token without any custom claims */
109-
$repository = new AccessTokenRepository(m::mock(TokenRepository::class), m::mock(Dispatcher::class));
110-
$client = new Client('client-id', 'name', 'redirect');
109+
$repository = new AccessTokenRepository(m::mock(Dispatcher::class));
110+
$client = new Client('client-id', 'name', ['redirect']);
111111
$keys = (new RSA())->createKey(2048);
112112
$token = $repository->getNewToken($client, [], '');
113113
$token->setPrivateKey(new CryptKey($keys['privatekey']));
@@ -130,8 +130,8 @@ public function test_exception_is_thrown_if_claim_does_not_match_value()
130130
$this->expectException(AuthenticationException::class);
131131

132132
/* set up token with custom claim */
133-
$repository = new AccessTokenRepository(m::mock(TokenRepository::class), m::mock(Dispatcher::class));
134-
$client = new Client('client-id', 'name', 'redirect');
133+
$repository = new AccessTokenRepository(m::mock(Dispatcher::class));
134+
$client = new Client('client-id', 'name', ['redirect']);
135135
$keys = (new RSA())->createKey(2048);
136136
app('config')->set('passport-claims.claims', [MyClaim::class]);
137137
$token = $repository->getNewToken($client, [], '');

0 commit comments

Comments
 (0)