Skip to content

Commit 5bd3f91

Browse files
Remove unused claims
1 parent f2d22bd commit 5bd3f91

2 files changed

Lines changed: 2 additions & 8 deletions

File tree

src/Security/Auth/TokenService.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ public function generateToken(ApiUser $user): string
7070
->identifiedBy(bin2hex(random_bytes(16)))
7171
->issuedAt($now)
7272
->expiresAt($now->modify(sprintf('+%d seconds', $this->expirationSeconds)))
73-
->withClaim('uid', $user->getUserId())
7473
->withClaim('username', $user->getUserIdentifier())
75-
->withClaim('roles', $user->getRoles())
7674
->getToken($this->config->signer(), $this->config->signingKey());
7775

7876
return $token->toString();

tests/Unit/Security/TokenServiceTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ public function testGenerateTokenWithAdminRole(): void
5858

5959
$parsedToken = $this->tokenService->parseToken($token);
6060

61-
$this->assertSame('admin123', $parsedToken->claims()->get('uid'));
6261
$this->assertSame('admin@example.com', $parsedToken->claims()->get('username'));
63-
$this->assertSame(['ROLE_USER', 'ROLE_ADMIN'], $parsedToken->claims()->get('roles'));
62+
$this->assertFalse($parsedToken->claims()->has('uid'));
63+
$this->assertFalse($parsedToken->claims()->has('roles'));
6464
}
6565

6666
public function testParseValidToken(): void
@@ -70,9 +70,7 @@ public function testParseValidToken(): void
7070
$token = $this->tokenService->generateToken($user);
7171
$parsedToken = $this->tokenService->parseToken($token);
7272

73-
$this->assertSame('user456', $parsedToken->claims()->get('uid'));
7473
$this->assertSame('user@example.com', $parsedToken->claims()->get('username'));
75-
$this->assertSame(['ROLE_USER'], $parsedToken->claims()->get('roles'));
7674
}
7775

7876
public function testParseInvalidToken(): void
@@ -208,9 +206,7 @@ public function testParseExpiredToken(): void
208206
->identifiedBy(bin2hex(random_bytes(16)))
209207
->issuedAt($now->modify('-2 hours'))
210208
->expiresAt($now->modify('-1 hour'))
211-
->withClaim('uid', 'user123')
212209
->withClaim('username', 'test@example.com')
213-
->withClaim('roles', ['ROLE_USER'])
214210
->getToken($config->signer(), $config->signingKey())
215211
->toString();
216212

0 commit comments

Comments
 (0)