Skip to content

Commit f86d7ce

Browse files
committed
Add JWT authentication
1 parent 0acb897 commit f86d7ce

File tree

3 files changed

+100
-1
lines changed

3 files changed

+100
-1
lines changed

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"api-clients/transport": "^3.1",
2525
"api-clients/travis": "^1.0",
2626
"kelunik/link-header-rfc5988": "^1.0",
27+
"lcobucci/jwt": "^3.3",
2728
"react/promise-stream": "^1.0 || ^0.1.1",
2829
"wyrihaximus/react-stream-base64": "^1.0",
2930
"wyrihaximus/react-stream-json": "^1.0"

composer.lock

+60-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Authentication/JWT.php

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ApiClients\Client\Github\Authentication;
4+
5+
use ApiClients\Client\Github\AuthenticationInterface;
6+
use ApiClients\Foundation\Options as FoundationOptions;
7+
use ApiClients\Foundation\Transport\Options as TransportOptions;
8+
use ApiClients\Middleware\BearerAuthorization\BearerAuthorizationHeaderMiddleware;
9+
use ApiClients\Middleware\BearerAuthorization\Options as BearerAuthorizationHeaderMiddlewareOptions;
10+
use Lcobucci\JWT\Token;
11+
12+
final class JWT implements AuthenticationInterface
13+
{
14+
/**
15+
* @var Token
16+
*/
17+
private $token;
18+
19+
public function __construct(Token $token)
20+
{
21+
$this->token = $token;
22+
}
23+
24+
public function getOptions(): array
25+
{
26+
return [
27+
FoundationOptions::TRANSPORT_OPTIONS => [
28+
TransportOptions::MIDDLEWARE => [
29+
BearerAuthorizationHeaderMiddleware::class,
30+
],
31+
TransportOptions::DEFAULT_REQUEST_OPTIONS => [
32+
BearerAuthorizationHeaderMiddleware::class => [
33+
BearerAuthorizationHeaderMiddlewareOptions::TOKEN => $this->token,
34+
],
35+
],
36+
],
37+
];
38+
}
39+
}

0 commit comments

Comments
 (0)