Skip to content

Commit 78b149e

Browse files
committed
Update docs
1 parent 3220aab commit 78b149e

File tree

2 files changed

+65
-4
lines changed

2 files changed

+65
-4
lines changed

docs/3-federation.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,60 @@ try {
285285
}
286286

287287
```
288+
289+
## Prepare Entity Statements
290+
291+
You can use an Entity Statement Factory to quickly create Entity Statements.
292+
Since Entity Statements are signed JWTs (JWS), you have to have your private
293+
key prepared which will be used to sign them.
294+
295+
```php
296+
297+
use SimpleSAML\OpenID\Codebooks\ClaimsEnum;
298+
use SimpleSAML\OpenID\Jwk;
299+
use SimpleSAML\OpenID\Algorithms\SignatureAlgorithmEnum;
300+
301+
/** @var \SimpleSAML\OpenID\Federation $federationTools */
302+
303+
// You can use the JWK Tools to create a JWK decorator from a private key file.
304+
$jwkTools = new Jwk();
305+
306+
// Prepare a signing key decorator. Check other methods on `jwkDecoratorFactory`
307+
// for alternative ways to create a key decorator.
308+
$signingKey = $jwkTools->jwkDecoratorFactory()->fromPkcs1Or8KeyFile(
309+
'/path/to/private/key.pem',
310+
);
311+
312+
// Set the signature algorithm to use.
313+
$signatureAlgorithm = SignatureAlgorithmEnum::ES256;
314+
315+
// Use any logic necessary to prepare JWT payload data.
316+
$issuedAt = new DateTimeImmutable('now', new DateTimeZone('UTC'));
317+
318+
$jwtPayload = [
319+
ClaimsEnum::Iss->value => 'https://example.com/issuer',
320+
ClaimsEnum::Iat->value => $issuedAt->getTimestamp(),
321+
ClaimsEnum::Nbf->value => $issuedAt->getTimestamp(),
322+
ClaimsEnum::Sub->value => 'subject-id',
323+
// ...
324+
];
325+
326+
// Use any logic necessary to prepare JWT header data.
327+
$jwtHeader = [
328+
ClaimsEnum::Kid->value 'abc123',
329+
//...
330+
];
331+
332+
// Build Entity Statement instance.
333+
$entityStatement = $federationTools->entityStatementFactory()->fromData(
334+
$signingKey,
335+
$signatureAlgorithm,
336+
$jwtPayload,
337+
$jwtHeader,
338+
);
339+
340+
// Get Entity Statement token string (JWS). Default serialization is
341+
// JwsSerializerEnum::Compact.
342+
$entityStatementToken = $entityStatement->getToken();
343+
344+
```

docs/4-vci.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ $verifiableCredentialTools = new VerifiableCredentials(
4242
$timestampValidationLeeway,
4343
);
4444

45-
// You can also use the JWK Tools to create a JWK decorator from a private key file.
45+
// You can also use the JWK Tools to create a JWK decorator from a private key
46+
// file.
4647
$jwkTools = new Jwk();
4748
```
4849

@@ -56,6 +57,7 @@ The following example shows how to create a SD-JWT VC.
5657
```php
5758

5859
use SimpleSAML\OpenID\Codebooks\ClaimsEnum;
60+
use SimpleSAML\OpenID\Algorithms\SignatureAlgorithmEnum;
5961

6062
/** @var \SimpleSAML\OpenID\VerifiableCredentials $verifiableCredentialTools */
6163
/** @var \SimpleSAML\OpenID\Jwk $jwkTools */
@@ -81,7 +83,7 @@ foreach ($disclosedData as $key => $value) {
8183
$disclosureBag->add($disclosure);
8284
}
8385

84-
$issuedAt = new \DateTimeImmutable();
86+
$issuedAt = new DateTimeImmutable('now', new DateTimeZone('UTC'));
8587

8688
// Use any logic necessary to prepare basic JWT payload data.
8789
$jwtPayload = [
@@ -94,8 +96,9 @@ $jwtPayload = [
9496
// ...
9597
];
9698

97-
// Use any logic necessary to prepare SD JWT header data.
99+
// Use any logic necessary to prepare JWT header data.
98100
$jwtHeader = [
101+
ClaimsEnum::Kid->value 'abc123',
99102
//...
100103
];
101104

@@ -116,6 +119,7 @@ $verifiableCredential = $verifiableCredentialTools->sdJwtVcFactory()->fromData(
116119
$disclosureBag,
117120
);
118121

119-
// Get the credential token string.
122+
// Get the credential token string (JWS). Default serialization is
123+
// JwsSerializerEnum::Compact.
120124
$token = $verifiableCredential->getToken();
121125
```

0 commit comments

Comments
 (0)