feat: read BusProNet base data from the MyE&P API
This commit is contained in:
1 parent
1505f9b50b
commit
2e9328fc51
37 files changed
+2302
-148
No files matched your search
@@ -12,7 +12,6 @@ use App\Security\OAuth2\MyEpClient;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Flagception\Manager\FeatureManagerInterface;
|
||||
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
|
||||
use Psr\Http\Client\ClientExceptionInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@@ -26,6 +25,8 @@ use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
|
||||
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
|
||||
use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport;
|
||||
use Symfony\Component\Security\Http\Util\TargetPathTrait;
|
||||
use Symfony\Contracts\HttpClient\Exception\ExceptionInterface as HttpExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
class MyEpAuthenticator extends AbstractAuthenticator
|
||||
{
|
||||
@@ -46,6 +47,7 @@ class MyEpAuthenticator extends AbstractAuthenticator
|
||||
|
||||
public function __construct(
|
||||
private readonly MyEpClient $client,
|
||||
private readonly HttpClientInterface $myepClient,
|
||||
private readonly UserDataHandler $userDataHandler,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly UrlGeneratorInterface $urlGenerator,
|
||||
@@ -84,25 +86,22 @@ class MyEpAuthenticator extends AbstractAuthenticator
|
||||
throw new CustomUserMessageAuthenticationException('Login via MyE&P nicht möglich');
|
||||
}
|
||||
|
||||
// A plain bearer request over the shared MyE&P client, so it inherits its
|
||||
// timeouts and transport retries. It deliberately does not go through
|
||||
// App\MyEp\Api\ApiClient: this token was just minted for this one request, so
|
||||
// there is no cached token to renew on a 401, and every failure here ends in
|
||||
// the same message anyway. Logging stays on the audit channel, unlike the
|
||||
// machine to machine traffic - a login attempt belongs in the audit trail.
|
||||
try {
|
||||
$provider = $this->client->getProvider();
|
||||
$url = $provider->getResourceOwnerDetailsUrl($accessToken);
|
||||
$userinfoRequest = $provider->getAuthenticatedRequest('GET', $url, $accessToken, [
|
||||
'headers' => [
|
||||
'Accept' => 'application/json',
|
||||
'Content-Type' => 'application/json',
|
||||
],
|
||||
$response = $this->myepClient->request('GET', 'api/userinfo', [
|
||||
'auth_bearer' => $accessToken->getToken(),
|
||||
'headers' => ['Accept' => 'application/json'],
|
||||
]);
|
||||
$userinfo = $response->toArray();
|
||||
} catch (HttpExceptionInterface $e) {
|
||||
$this->logger->error('Login via MyE&P failed due to unexpected userinfo response', [
|
||||
'exception' => $e,
|
||||
]);
|
||||
$response = $provider->getHttpClient()->sendRequest($userinfoRequest);
|
||||
} catch (ClientExceptionInterface $e) {
|
||||
$this->logger->error('Login via MyE&P failed due to unexpected userinfo response');
|
||||
throw new CustomUserMessageAuthenticationException('Login via MyE&P nicht möglich');
|
||||
}
|
||||
|
||||
$userinfo = json_decode($response->getBody(), true);
|
||||
|
||||
if (false === is_array($userinfo)) {
|
||||
$this->logger->error('Login via MyE&P failed due to unreadable userinfo payload');
|
||||
throw new CustomUserMessageAuthenticationException('Login via MyE&P nicht möglich');
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user