From 7aab0ecf2f78ce58f28b53c1fa19bfd824cc3cd7 Mon Sep 17 00:00:00 2001 From: Bertrand Dunogier Date: Thu, 29 Sep 2016 10:14:43 +0200 Subject: Added authentication for restricted access articles Fix #438. Thank you so much @bdunogier --- .../GrabySiteConfigBuilder.php | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php (limited to 'src/Wallabag/CoreBundle/GuzzleSiteAuthenticator') diff --git a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php new file mode 100644 index 00000000..6d4129e8 --- /dev/null +++ b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php @@ -0,0 +1,68 @@ +grabyConfigBuilder = $grabyConfigBuilder; + $this->credentials = $credentials; + } + + /** + * Builds the SiteConfig for a host. + * + * @param string $host The "www." prefix is ignored + * + * @return SiteConfig + * + * @throws OutOfRangeException If there is no config for $host + */ + public function buildForHost($host) + { + // required by credentials below + $host = strtolower($host); + if (substr($host, 0, 4) == 'www.') { + $host = substr($host, 4); + } + + $config = $this->grabyConfigBuilder->buildForHost($host); + $parameters = [ + 'host' => $host, + 'requiresLogin' => $config->requires_login ?: false, + 'loginUri' => $config->login_uri ?: null, + 'usernameField' => $config->login_username_field ?: null, + 'passwordField' => $config->login_password_field ?: null, + 'extraFields' => is_array($config->login_extra_fields) ? $config->login_extra_fields : [], + 'notLoggedInXpath' => $config->not_logged_in_xpath ?: null, + ]; + + if (isset($this->credentials[$host])) { + $parameters['username'] = $this->credentials[$host]['username']; + $parameters['password'] = $this->credentials[$host]['password']; + } + + return new SiteConfig($parameters); + } +} -- cgit v1.2.3