@@ -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+ ```
0 commit comments