From f45496336f5bbd31b69553fcfae9cdfd03b280cc Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 23 Apr 2019 22:28:36 +0200 Subject: Add ability to match many domains for credentials MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of fetching one domain, we use the same method as in site config (to retrieve the matching file) and handle api.example.org, example.org, .org (yes the last one isn’t useful). If one of these match, we got it and use it. --- .../GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php') diff --git a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php index 90e00c62..718441bd 100644 --- a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php +++ b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php @@ -64,7 +64,17 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder $credentials = null; if ($this->currentUser) { - $credentials = $this->credentialRepository->findOneByHostAndUser($host, $this->currentUser->getId()); + $hosts = [$host]; + // will try to see for a host without the first subdomain (fr.example.org & .example.org) + $split = explode('.', $host); + + if (\count($split) > 1) { + // remove first subdomain + array_shift($split); + $hosts[] = '.' . implode('.', $split); + } + + $credentials = $this->credentialRepository->findOneByHostsAndUser($hosts, $this->currentUser->getId()); } if (null === $credentials) { -- cgit v1.2.3 From 35359bd3c67e5b6c6371e2e547a3411ca0a8027b Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 24 Apr 2019 15:28:15 +0200 Subject: Adding more tests to cover different scenario --- .../GrabySiteConfigBuilder.php | 27 ++++++++++++---------- 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php') diff --git a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php index 718441bd..c7502bac 100644 --- a/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php +++ b/src/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilder.php @@ -62,21 +62,24 @@ class GrabySiteConfigBuilder implements SiteConfigBuilder $host = substr($host, 4); } - $credentials = null; - if ($this->currentUser) { - $hosts = [$host]; - // will try to see for a host without the first subdomain (fr.example.org & .example.org) - $split = explode('.', $host); - - if (\count($split) > 1) { - // remove first subdomain - array_shift($split); - $hosts[] = '.' . implode('.', $split); - } + if (!$this->currentUser) { + $this->logger->debug('Auth: no current user defined.'); + + return false; + } + + $hosts = [$host]; + // will try to see for a host without the first subdomain (fr.example.org & .example.org) + $split = explode('.', $host); - $credentials = $this->credentialRepository->findOneByHostsAndUser($hosts, $this->currentUser->getId()); + if (\count($split) > 1) { + // remove first subdomain + array_shift($split); + $hosts[] = '.' . implode('.', $split); } + $credentials = $this->credentialRepository->findOneByHostsAndUser($hosts, $this->currentUser->getId()); + if (null === $credentials) { $this->logger->debug('Auth: no credentials available for host.', ['host' => $host]); -- cgit v1.2.3