aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Helper
diff options
context:
space:
mode:
authorBertrand Dunogier <bertrand.dunogier@gmail.com>2016-09-29 10:14:43 +0200
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2016-11-22 14:01:46 +0100
commit7aab0ecf2f78ce58f28b53c1fa19bfd824cc3cd7 (patch)
treeb3e4f7875944f79e6f4fcf16fd5d1230a1467621 /src/Wallabag/CoreBundle/Helper
parentbb28368f6953e07dbe6747d7c1eacf1abe35817e (diff)
downloadwallabag-7aab0ecf2f78ce58f28b53c1fa19bfd824cc3cd7.tar.gz
wallabag-7aab0ecf2f78ce58f28b53c1fa19bfd824cc3cd7.tar.zst
wallabag-7aab0ecf2f78ce58f28b53c1fa19bfd824cc3cd7.zip
Added authentication for restricted access articles
Fix #438. Thank you so much @bdunogier
Diffstat (limited to 'src/Wallabag/CoreBundle/Helper')
-rw-r--r--src/Wallabag/CoreBundle/Helper/HttpClientFactory.php44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php b/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php
new file mode 100644
index 00000000..3e1d1ed5
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php
@@ -0,0 +1,44 @@
1<?php
2
3namespace Wallabag\CoreBundle\Helper;
4
5use Graby\Ring\Client\SafeCurlHandler;
6use GuzzleHttp\Client;
7use GuzzleHttp\Cookie\CookieJar;
8use GuzzleHttp\Event\SubscriberInterface;
9
10/**
11 * Builds and configures the Guzzle HTTP client.
12 */
13class HttpClientFactory
14{
15 /** @var \GuzzleHttp\Event\SubscriberInterface */
16 private $authenticatorSubscriber;
17
18 /** @var \GuzzleHttp\Cookie\CookieJar */
19 private $cookieJar;
20
21 /**
22 * HttpClientFactory constructor.
23 *
24 * @param \GuzzleHttp\Event\SubscriberInterface $authenticatorSubscriber
25 * @param \GuzzleHttp\Cookie\CookieJar $cookieJar
26 */
27 public function __construct(SubscriberInterface $authenticatorSubscriber, CookieJar $cookieJar)
28 {
29 $this->authenticatorSubscriber = $authenticatorSubscriber;
30 $this->cookieJar = $cookieJar;
31 }
32
33 /**
34 * @return \GuzzleHttp\Client
35 */
36 public function buildHttpClient()
37 {
38 // need to set the (shared) cookie jar
39 $client = new Client(['handler' => new SafeCurlHandler(), 'defaults' => ['cookies' => $this->cookieJar]]);
40 $client->getEmitter()->attach($this->authenticatorSubscriber);
41
42 return $client;
43 }
44}