Skip to content

Commit 5ec0bfb

Browse files
committed
Introduce hasKeyId on JwksClaim
1 parent 3eabe48 commit 5ec0bfb

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/Claims/JwksClaim.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,19 @@ public function jsonSerialize(): array
4646
$this->name => $this->value,
4747
];
4848
}
49+
50+
51+
/**
52+
* Check whether the JWKS contains a key with the given key ID.
53+
*/
54+
public function hasKeyId(string $keyId): bool
55+
{
56+
foreach ($this->value[ClaimsEnum::Keys->value] as $key) {
57+
if ($key[ClaimsEnum::Kid->value] === $keyId) {
58+
return true;
59+
}
60+
}
61+
62+
return false;
63+
}
4964
}

tests/src/Claims/JwksClaimTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,13 @@ public function testCanGetProperties(): void
6565
$this->sut()->jsonSerialize(),
6666
);
6767
}
68+
69+
70+
public function testCanCheckIfKeyIdExists(): void
71+
{
72+
$sut = $this->sut();
73+
74+
$this->assertTrue($sut->hasKeyId('F4VFObNusj3PHmrHxpqh4GNiuFHlfh-2s6xMJ95fLYA'));
75+
$this->assertFalse($sut->hasKeyId('invalid-key-id'));
76+
}
6877
}

0 commit comments

Comments
 (0)