Skip to content

Commit de96379

Browse files
authored
minor KnpLabs#1017 Update integration authentication documentation for usage with lcobucci/jwt ^4 (glaubinix)
This PR was squashed before being merged into the 3.4.x-dev branch. Discussion ---------- The security docs were mentioning `lcobucci/jwt:^3.4` which doesn't support php 8. Updated the security docs to reflect all necessary changes to work with `lcobucci/jwt:^4.1` Passing `ChainedFormatter::withUnixTimestampDates()` to the builder method is necessary because otherwise all dates will be format via `$date->format('U.u')` as microseconds. GitHub expects unix timestamps and will return a 401 response with `'Expiration time' claim ('exp') must be a numeric value representing the future time at which the assertion expires`. Commits ------- 917192c Update integration authentication documentation for usage with lcobucci/jwt ^4 73dea74 Docs: add builder to JWT authentication
1 parent c52f9b7 commit de96379

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

doc/security.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,18 @@ and installation access token which is then usable with `Github\Client::AUTH_ACC
3737
authentication docs](https://developer.github.com/apps/building-github-apps/authentication-options-for-github-apps/#authenticating-as-a-github-app) describe the flow in detail.
3838
It´s important for integration requests to use the custom Accept header `application/vnd.github.machine-man-preview`.
3939

40-
The following sample code authenticates as an installation using [lcobucci/jwt 3.4](https://github.com/lcobucci/jwt/tree/3.4)
40+
The following sample code authenticates as an installation using [lcobucci/jwt 4.1](https://github.com/lcobucci/jwt/tree/4.1.x)
4141
to generate a JSON Web Token (JWT).
4242

4343
```php
44+
use Github\HttpClient\Builder;
4445
use Lcobucci\JWT\Configuration;
46+
use Lcobucci\JWT\Encoding\ChainedFormatter;
4547
use Lcobucci\JWT\Signer\Key\LocalFileReference;
4648
use Lcobucci\JWT\Signer\Rsa\Sha256;
4749

50+
$builder = new Builder();
51+
4852
$github = new Github\Client($builder, 'machine-man-preview');
4953

5054
$config = Configuration::forSymmetricSigner(
@@ -53,14 +57,14 @@ $config = Configuration::forSymmetricSigner(
5357
);
5458

5559
$now = new \DateTimeImmutable();
56-
$jwt = $config->builder()
60+
$jwt = $config->builder(ChainedFormatter::withUnixTimestampDates())
5761
->issuedBy($integrationId)
5862
->issuedAt($now)
5963
->expiresAt($now->modify('+1 minute'))
6064
->getToken($config->signer(), $config->signingKey())
6165
;
6266

63-
$github->authenticate($jwt, null, Github\Client::AUTH_JWT)
67+
$github->authenticate($jwt->toString(), null, Github\Client::AUTH_JWT)
6468
```
6569

6670
The `$integrationId` you can find in the about section of your github app.

0 commit comments

Comments
 (0)