Skip to content

Commit 1b853a3

Browse files
[952] doc - Specify lcobucci/jwt version, fix deprecation
Update "integrating with app" example to use lcobucci/jwt 3.4 Fix whitespace formatting update example for compatibility with both 3.4.x and 4.x
1 parent 60d0d5f commit 1b853a3

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

doc/security.md

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,30 +55,28 @@ 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+
$jwt = $config->builder()
74+
->issuedBy($integrationId)
75+
->issuedAt(time())
76+
->expiresAt(time() + 60)
77+
->getToken($config->signer(), $config->signingKey()));
7978

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

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

0 commit comments

Comments
 (0)