Skip to content

Commit d343143

Browse files
bug KnpLabs#953 [952] doc - Specify lcobucci/jwt version, fix deprecation (amacrobert-meq, acrobat)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- Fixes KnpLabs#952 Commits ------- 1b853a3 [952] doc - Specify lcobucci/jwt version, fix deprecation 408f0b7 Merge branch '2.x' into 952-integration-doc-update 25ba522 Apply latest changes b6ebc9b Merge remote-tracking branch 'upstream/2.x' into amacrobert-meq--952-integration-doc-update
1 parent fd4d2a8 commit d343143

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
@@ -55,30 +55,30 @@ and installation access token which is then usable with `Github\Client::AUTH_ACC
5555
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.
5656
It´s important for integration requests to use the custom Accept header `application/vnd.github.machine-man-preview`.
5757

58-
The following sample code authenticates as an installation using [lcobucci/jwt](https://github.com/lcobucci/jwt/tree/3.3.2)
58+
The following sample code authenticates as an installation using [lcobucci/jwt 3.4](https://github.com/lcobucci/jwt/tree/3.4)
5959
to generate a JSON Web Token (JWT).
6060

6161
```php
62-
use Http\Adapter\Guzzle6\Client as GuzzleClient;
63-
use Lcobucci\JWT\Builder;
64-
use Lcobucci\JWT\Signer\Key;
62+
use Lcobucci\JWT\Configuration;
63+
use Lcobucci\JWT\Signer\Key\LocalFileReference;
6564
use Lcobucci\JWT\Signer\Rsa\Sha256;
6665

67-
$builder = new Github\HttpClient\Builder(new GuzzleClient());
6866
$github = new Github\Client($builder, 'machine-man-preview');
6967

70-
$jwt = (new Builder)
71-
->setIssuer($integrationId)
72-
->setIssuedAt(time())
73-
->setExpiration(time() + 60)
74-
// `file://` prefix for file path or file contents itself
75-
->sign(new Sha256(), new Key('file:///path/to/integration.private-key.pem'))
76-
->getToken();
68+
$config = Configuration::forSymmetricSigner(
69+
new Sha256(),
70+
LocalFileReference::file('path/to/integration.private-key.pem')
71+
);
7772

78-
$github->authenticate($jwt, null, Github\Client::AUTH_JWT);
73+
$now = new \DateTimeImmutable();
74+
$jwt = $config->builder()
75+
->issuedBy($integrationId)
76+
->issuedAt($now)
77+
->expiresAt($now->modify('+1 minute'))
78+
->getToken($config->signer(), $config->signingKey())
79+
;
7980

80-
$token = $github->api('apps')->createInstallationToken($installationId);
81-
$github->authenticate($token['token'], null, Github\Client::AUTH_ACCESS_TOKEN);
81+
$github->authenticate($jwt, null, Github\Client::AUTH_JWT)
8282
```
8383

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

0 commit comments

Comments
 (0)