Skip to content

Commit 017ad9d

Browse files
committed
Fix client credentials
In `league/server-bundle` version `0.8`, when the client_credentials grant is used, the `sub` claim of the JWT is an empty string, but in version `0.9` is filled with the client ID. We override the `getSubjectIdentifier` of the AccessToken entity to return an empty string again when the client_credentials grant is used.
1 parent 3f88e38 commit 017ad9d

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/Entity/AccessToken.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@ final class AccessToken implements AccessTokenEntityInterface
1414
use AccessTokenTrait;
1515
use EntityTrait;
1616
use TokenEntityTrait;
17+
18+
public function getSubjectIdentifier(): string
19+
{
20+
return $this->userIdentifier ?? '';
21+
}
1722
}

tests/Integration/ResourceServerTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,20 @@ public function testRevokedAccessToken(): void
9595

9696
$this->assertNull($request);
9797
}
98+
99+
public function testValidClientCredentialsGrant(): void
100+
{
101+
$tokenResponse = $this->handleTokenRequest(
102+
$this->createAuthorizationRequest(null, [
103+
'client_id' => 'foo',
104+
'client_secret' => 'secret',
105+
'grant_type' => 'client_credentials',
106+
])
107+
);
108+
109+
$resourceRequest = $this->handleResourceRequest($this->createResourceRequest($tokenResponse['access_token']));
110+
$this->assertSame(FixtureFactory::FIXTURE_CLIENT_FIRST, $resourceRequest->getAttribute('oauth_client_id'));
111+
$this->assertSame('', $resourceRequest->getAttribute('oauth_user_id'));
112+
$this->assertSame([], $resourceRequest->getAttribute('oauth_scopes'));
113+
}
98114
}

0 commit comments

Comments
 (0)