Skip to content

Commit 23afc53

Browse files
committed
Merge branch '2.x'
* 2.x: bug KnpLabs#953 [952] doc - Specify lcobucci/jwt version, fix deprecation (amacrobert-meq, acrobat)
2 parents 7b84f9c + d343143 commit 23afc53

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

doc/security.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,30 +37,30 @@ 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](https://github.com/lcobucci/jwt/tree/3.3.2)
40+
The following sample code authenticates as an installation using [lcobucci/jwt 3.4](https://github.com/lcobucci/jwt/tree/3.4)
4141
to generate a JSON Web Token (JWT).
4242

4343
```php
44-
use Http\Adapter\Guzzle6\Client as GuzzleClient;
45-
use Lcobucci\JWT\Builder;
46-
use Lcobucci\JWT\Signer\Key;
44+
use Lcobucci\JWT\Configuration;
45+
use Lcobucci\JWT\Signer\Key\LocalFileReference;
4746
use Lcobucci\JWT\Signer\Rsa\Sha256;
4847

49-
$builder = new Github\HttpClient\Builder(new GuzzleClient());
5048
$github = new Github\Client($builder, 'machine-man-preview');
5149

52-
$jwt = (new Builder)
53-
->setIssuer($integrationId)
54-
->setIssuedAt(time())
55-
->setExpiration(time() + 60)
56-
// `file://` prefix for file path or file contents itself
57-
->sign(new Sha256(), new Key('file:///path/to/integration.private-key.pem'))
58-
->getToken();
50+
$config = Configuration::forSymmetricSigner(
51+
new Sha256(),
52+
LocalFileReference::file('path/to/integration.private-key.pem')
53+
);
5954

60-
$github->authenticate($jwt, null, Github\Client::AUTH_JWT);
55+
$now = new \DateTimeImmutable();
56+
$jwt = $config->builder()
57+
->issuedBy($integrationId)
58+
->issuedAt($now)
59+
->expiresAt($now->modify('+1 minute'))
60+
->getToken($config->signer(), $config->signingKey())
61+
;
6162

62-
$token = $github->api('apps')->createInstallationToken($installationId);
63-
$github->authenticate($token['token'], null, Github\Client::AUTH_ACCESS_TOKEN);
63+
$github->authenticate($jwt, null, Github\Client::AUTH_JWT)
6464
```
6565

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

0 commit comments

Comments
 (0)