ci: add php cs fixer

This commit is contained in:
Maël Gangloff
2024-08-02 23:24:52 +02:00
parent cd5060ed6a
commit b460e8aaa6
41 changed files with 1413 additions and 440 deletions

View File

@@ -20,17 +20,15 @@ use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport;
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
class OAuthAuthenticator extends OAuth2Authenticator implements AuthenticationEntrypointInterface
class OAuthAuthenticator extends OAuth2Authenticator implements AuthenticationEntryPointInterface
{
public function __construct(
private readonly ClientRegistry $clientRegistry,
private readonly UserRepository $userRepository,
private readonly EntityManagerInterface $em,
private readonly RouterInterface $router,
private readonly ClientRegistry $clientRegistry,
private readonly UserRepository $userRepository,
private readonly EntityManagerInterface $em,
private readonly RouterInterface $router,
private readonly JWTTokenManagerInterface $JWTManager
)
{
) {
}
/**
@@ -40,7 +38,7 @@ class OAuthAuthenticator extends OAuth2Authenticator implements AuthenticationEn
*/
public function supports(Request $request): ?bool
{
return $request->attributes->get('_route') === 'oauth_connect_check';
return 'oauth_connect_check' === $request->attributes->get('_route');
}
public function authenticate(Request $request): Passport
@@ -50,13 +48,14 @@ class OAuthAuthenticator extends OAuth2Authenticator implements AuthenticationEn
return new SelfValidatingPassport(
new UserBadge($accessToken->getToken(), function () use ($accessToken, $client) {
/** @var OAuthResourceOwner $userFromToken */
$userFromToken = $client->fetchUserFromToken($accessToken);
$existingUser = $this->userRepository->findOneBy(['email' => $userFromToken->getEmail()]);
if ($existingUser) return $existingUser;
if ($existingUser) {
return $existingUser;
}
$user = new User();
$user->setEmail($userFromToken->getEmail());
@@ -85,6 +84,7 @@ class OAuthAuthenticator extends OAuth2Authenticator implements AuthenticationEn
'strict'
)
);
return $response;
}

View File

@@ -13,11 +13,9 @@ class OAuthProvider extends AbstractProvider
{
use BearerAuthorizationTrait;
public function __construct(private readonly array $options = [], array $collaborators = [])
{
parent::__construct($options, $collaborators);
}
public function getBaseAuthorizationUrl(): string
@@ -43,11 +41,7 @@ class OAuthProvider extends AbstractProvider
protected function checkResponse(ResponseInterface $response, $data): void
{
if ($response->getStatusCode() >= 400) {
throw new IdentityProviderException(
$data['error'] ?? 'Unknown error',
$response->getStatusCode(),
$response
);
throw new IdentityProviderException($data['error'] ?? 'Unknown error', $response->getStatusCode(), $response);
}
}
@@ -55,4 +49,4 @@ class OAuthProvider extends AbstractProvider
{
return new OAuthResourceOwner($response);
}
}
}

View File

@@ -37,4 +37,4 @@ class OAuthResourceOwner implements ResourceOwnerInterface
{
return $this->response['name'];
}
}
}