Skip to content

Update integration authentication documentation for usage with lcobucci/jwt ^4 #1017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions doc/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@ and installation access token which is then usable with `Github\Client::AUTH_ACC
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.
It´s important for integration requests to use the custom Accept header `application/vnd.github.machine-man-preview`.

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

```php
use Github\HttpClient\Builder;
use Lcobucci\JWT\Configuration;
use Lcobucci\JWT\Encoding\ChainedFormatter;
use Lcobucci\JWT\Signer\Key\LocalFileReference;
use Lcobucci\JWT\Signer\Rsa\Sha256;

$builder = new Builder();

$github = new Github\Client($builder, 'machine-man-preview');

$config = Configuration::forSymmetricSigner(
Expand All @@ -53,14 +57,14 @@ $config = Configuration::forSymmetricSigner(
);

$now = new \DateTimeImmutable();
$jwt = $config->builder()
$jwt = $config->builder(ChainedFormatter::withUnixTimestampDates())
->issuedBy($integrationId)
->issuedAt($now)
->expiresAt($now->modify('+1 minute'))
->getToken($config->signer(), $config->signingKey())
;

$github->authenticate($jwt, null, Github\Client::AUTH_JWT)
$github->authenticate($jwt->toString(), null, Github\Client::AUTH_JWT)
```

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