Skip to content

Commit

Permalink
Merge pull request #69 from php-api-clients/jwt-bear-auth
Browse files Browse the repository at this point in the history
Add JWT authentication
  • Loading branch information
WyriHaximus authored Apr 3, 2020
2 parents 0acb897 + f86d7ce commit 6978d50
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 1 deletion.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"api-clients/transport": "^3.1",
"api-clients/travis": "^1.0",
"kelunik/link-header-rfc5988": "^1.0",
"lcobucci/jwt": "^3.3",
"react/promise-stream": "^1.0 || ^0.1.1",
"wyrihaximus/react-stream-base64": "^1.0",
"wyrihaximus/react-stream-json": "^1.0"
Expand Down
61 changes: 60 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions src/Authentication/JWT.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php declare(strict_types=1);

namespace ApiClients\Client\Github\Authentication;

use ApiClients\Client\Github\AuthenticationInterface;
use ApiClients\Foundation\Options as FoundationOptions;
use ApiClients\Foundation\Transport\Options as TransportOptions;
use ApiClients\Middleware\BearerAuthorization\BearerAuthorizationHeaderMiddleware;
use ApiClients\Middleware\BearerAuthorization\Options as BearerAuthorizationHeaderMiddlewareOptions;
use Lcobucci\JWT\Token;

final class JWT implements AuthenticationInterface
{
/**
* @var Token
*/
private $token;

public function __construct(Token $token)
{
$this->token = $token;
}

public function getOptions(): array
{
return [
FoundationOptions::TRANSPORT_OPTIONS => [
TransportOptions::MIDDLEWARE => [
BearerAuthorizationHeaderMiddleware::class,
],
TransportOptions::DEFAULT_REQUEST_OPTIONS => [
BearerAuthorizationHeaderMiddleware::class => [
BearerAuthorizationHeaderMiddlewareOptions::TOKEN => $this->token,
],
],
],
];
}
}

0 comments on commit 6978d50

Please sign in to comment.