Skip to content

Commit

Permalink
Fix client credentials
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ajgarlag committed Jan 21, 2025
1 parent 3f88e38 commit 017ad9d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Entity/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ final class AccessToken implements AccessTokenEntityInterface
use AccessTokenTrait;
use EntityTrait;
use TokenEntityTrait;

public function getSubjectIdentifier(): string
{
return $this->userIdentifier ?? '';
}
}
16 changes: 16 additions & 0 deletions tests/Integration/ResourceServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,20 @@ public function testRevokedAccessToken(): void

$this->assertNull($request);
}

public function testValidClientCredentialsGrant(): void
{
$tokenResponse = $this->handleTokenRequest(
$this->createAuthorizationRequest(null, [
'client_id' => 'foo',
'client_secret' => 'secret',
'grant_type' => 'client_credentials',
])
);

$resourceRequest = $this->handleResourceRequest($this->createResourceRequest($tokenResponse['access_token']));
$this->assertSame(FixtureFactory::FIXTURE_CLIENT_FIRST, $resourceRequest->getAttribute('oauth_client_id'));
$this->assertSame('', $resourceRequest->getAttribute('oauth_user_id'));
$this->assertSame([], $resourceRequest->getAttribute('oauth_scopes'));
}
}

0 comments on commit 017ad9d

Please sign in to comment.