-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #290 from cultuurnet/III-6220-generic-management-t…
…oken III-6220 Refactor ManagementToken as preparation for Keycloak
- Loading branch information
Showing
21 changed files
with
522 additions
and
560 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CultuurNet\UDB3\Search\Http\Authentication\Auth0; | ||
|
||
use CultuurNet\UDB3\Search\Http\Authentication\MetadataGenerator; | ||
use CultuurNet\UDB3\Search\Json; | ||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Exception\ConnectException; | ||
use GuzzleHttp\Psr7\Request; | ||
use Psr\Log\LoggerAwareInterface; | ||
use Psr\Log\LoggerAwareTrait; | ||
use Psr\Log\NullLogger; | ||
|
||
final class Auth0MetadataGenerator implements MetadataGenerator, LoggerAwareInterface | ||
{ | ||
use LoggerAwareTrait; | ||
|
||
private Client $client; | ||
|
||
private string $domain; | ||
|
||
public function __construct( | ||
Client $client, | ||
string $domain | ||
) { | ||
$this->domain = $domain; | ||
$this->client = $client; | ||
$this->logger = new NullLogger(); | ||
} | ||
|
||
public function get(string $clientId, string $token): ?array | ||
{ | ||
$response = $this->client->get( | ||
'https://' . $this->domain . '/api/v2/clients/' . $clientId, | ||
[ | ||
'headers' => ['Authorization' => 'Bearer ' . $token], | ||
] | ||
); | ||
|
||
if ($response->getStatusCode() !== 200) { | ||
$message = 'Auth0 error when getting metadata: ' . $response->getStatusCode(); | ||
|
||
if ($response->getStatusCode() >= 500) { | ||
$this->logger->error($message); | ||
throw new ConnectException( | ||
$message, | ||
new Request('GET', 'https://' . $this->domain . '/api/v2/clients/' . $clientId) | ||
); | ||
} | ||
|
||
$this->logger->info($message); | ||
return null; | ||
} | ||
|
||
$res = Json::decodeAssociatively($response->getBody()->getContents()); | ||
return $res['client_metadata'] ?? []; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/Http/Authentication/ManagementToken/ManagementTokenGenerator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CultuurNet\UDB3\Search\Http\Authentication\ManagementToken; | ||
|
||
interface ManagementTokenGenerator | ||
{ | ||
public function newToken(): ManagementToken; | ||
} |
Oops, something went wrong.