mirror of
https://github.com/wallabag/wallabag.git
synced 2025-09-15 18:57:05 +00:00
Use Graby's http headers configuration for the authentication request
This commit is contained in:
parent
b905a2c856
commit
d58549472c
5 changed files with 96 additions and 1 deletions
|
@ -85,6 +85,7 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder
|
|||
'notLoggedInXpath' => $config->not_logged_in_xpath ?: null,
|
||||
'username' => $credentials['username'],
|
||||
'password' => $credentials['password'],
|
||||
'httpHeaders' => $config->http_header,
|
||||
];
|
||||
|
||||
$config = new SiteConfig($parameters);
|
||||
|
|
|
@ -30,7 +30,7 @@ class LoginFormAuthenticator
|
|||
$siteConfig->getPasswordField() => $siteConfig->getPassword(),
|
||||
] + $this->getExtraFields($siteConfig);
|
||||
|
||||
$this->browser->request('POST', $siteConfig->getLoginUri(), $postFields);
|
||||
$this->browser->request('POST', $siteConfig->getLoginUri(), $postFields, [], $this->getHttpHeaders($siteConfig));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -73,6 +73,20 @@ class LoginFormAuthenticator
|
|||
return \count($loggedIn) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes http_header(*) config, prepending HTTP_ string to the header's name.
|
||||
* See : https://github.com/symfony/browser-kit/blob/5.4/AbstractBrowser.php#L349.
|
||||
*/
|
||||
protected function getHttpHeaders(SiteConfig $siteConfig): array
|
||||
{
|
||||
$headers = [];
|
||||
foreach ($siteConfig->getHttpHeaders() as $headerName => $headerValue) {
|
||||
$headers["HTTP_$headerName"] = $headerValue;
|
||||
}
|
||||
|
||||
return $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns extra fields from the configuration.
|
||||
* Evaluates any field value that is an expression language string.
|
||||
|
|
|
@ -70,6 +70,13 @@ class SiteConfig
|
|||
*/
|
||||
protected $password;
|
||||
|
||||
/**
|
||||
* Associative array of HTTP headers to send with the form.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $httpHeaders = [];
|
||||
|
||||
/**
|
||||
* SiteConfig constructor. Sets the properties by name given a hash.
|
||||
*
|
||||
|
@ -260,4 +267,16 @@ class SiteConfig
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getHttpHeaders(): array
|
||||
{
|
||||
return $this->httpHeaders;
|
||||
}
|
||||
|
||||
public function setHttpHeaders(array $httpHeaders): self
|
||||
{
|
||||
$this->httpHeaders = $httpHeaders;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue