Make AuthenticatorProvider use Symfony HTTP Client

This commit is contained in:
Yassine Guedidi
2024-12-23 00:02:59 +01:00
parent c2197bd020
commit 1e1d58da7f
5 changed files with 47 additions and 20 deletions

View File

@ -10,6 +10,13 @@ use Wallabag\ExpressionLanguage\AuthenticatorProvider;
class LoginFormAuthenticator
{
private AuthenticatorProvider $authenticatorProvider;
public function __construct(AuthenticatorProvider $authenticatorProvider)
{
$this->authenticatorProvider = $authenticatorProvider;
}
/**
* Logs the configured user on the given Guzzle client.
*
@ -20,7 +27,7 @@ class LoginFormAuthenticator
$postFields = [
$siteConfig->getUsernameField() => $siteConfig->getUsername(),
$siteConfig->getPasswordField() => $siteConfig->getPassword(),
] + $this->getExtraFields($siteConfig, $guzzle);
] + $this->getExtraFields($siteConfig);
$guzzle->post(
$siteConfig->getLoginUri(),
@ -77,13 +84,13 @@ class LoginFormAuthenticator
*
* @return array
*/
private function getExtraFields(SiteConfig $siteConfig, ClientInterface $guzzle)
private function getExtraFields(SiteConfig $siteConfig)
{
$extraFields = [];
foreach ($siteConfig->getExtraFields() as $fieldName => $fieldValue) {
if ('@=' === substr($fieldValue, 0, 2)) {
$expressionLanguage = $this->getExpressionLanguage($guzzle);
$expressionLanguage = $this->getExpressionLanguage();
$fieldValue = $expressionLanguage->evaluate(
substr($fieldValue, 2),
[
@ -101,11 +108,11 @@ class LoginFormAuthenticator
/**
* @return ExpressionLanguage
*/
private function getExpressionLanguage(ClientInterface $guzzle)
private function getExpressionLanguage()
{
return new ExpressionLanguage(
null,
[new AuthenticatorProvider($guzzle)]
[$this->authenticatorProvider]
);
}
}