Skip to content

Commit 55c90e7

Browse files
committed
WIP JwtVcJson
1 parent d2731fa commit 55c90e7

3 files changed

Lines changed: 41 additions & 0 deletions

File tree

src/Codebooks/ClaimsEnum.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,6 @@ enum ClaimsEnum: string
148148
case Use = 'use';
149149
case UserAuthentication = 'user_authentication';
150150
case UserinfoEndpoint = 'userinfo_endpoint';
151+
// VerifiableCredential
152+
case Vc = 'vc';
151153
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\OpenID\Exceptions;
6+
7+
class JwtVcJsonException extends JwsException
8+
{
9+
}

src/VerifiableCredentials/JwtVcJson.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
namespace SimpleSAML\OpenID\VerifiableCredentials;
66

7+
use SimpleSAML\OpenID\Codebooks\ClaimsEnum;
78
use SimpleSAML\OpenID\Codebooks\CredentialFormatIdentifiersEnum;
9+
use SimpleSAML\OpenID\Exceptions\JwtVcJsonException;
810
use SimpleSAML\OpenID\Jws\ParsedJws;
911

1012
class JwtVcJson extends ParsedJws implements VerifiableCredentialInterface
@@ -13,4 +15,32 @@ public function getCredentialFormatIdentifier(): CredentialFormatIdentifiersEnum
1315
{
1416
return CredentialFormatIdentifiersEnum::JwtVcJson;
1517
}
18+
19+
/**
20+
* @throws \SimpleSAML\OpenID\Exceptions\JwsException
21+
* @throws \SimpleSAML\OpenID\Exceptions\JwtVcJsonException
22+
* @return mixed[]
23+
*/
24+
public function getVc(): array
25+
{
26+
$claimKey = ClaimsEnum::Vc->value;
27+
28+
$vc = $this->getPayloadClaim($claimKey) ?? throw new JwtVcJsonException('No vc claim found.');
29+
30+
if (is_array($vc)) {
31+
return $vc;
32+
}
33+
34+
throw new JwtVcJsonException('Invalid vc claim.');
35+
}
36+
37+
/**
38+
* @throws \SimpleSAML\OpenID\Exceptions\JwsException
39+
*/
40+
protected function validate(): void
41+
{
42+
$this->validateByCallbacks(
43+
$this->getVc(...),
44+
);
45+
}
1646
}

0 commit comments

Comments
 (0)