mirror of https://github.com/wallabag/wallabag.git
Remove site config authenticator extension point
This commit is contained in:
parent
0c49aee192
commit
ac6969f4cc
|
@ -9,7 +9,7 @@ use GuzzleHttp\Message\RequestInterface;
|
||||||
use Psr\Log\LoggerAwareInterface;
|
use Psr\Log\LoggerAwareInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Psr\Log\NullLogger;
|
use Psr\Log\NullLogger;
|
||||||
use Wallabag\SiteConfig\Authenticator\Authenticator;
|
use Wallabag\SiteConfig\Authenticator\LoginFormAuthenticator;
|
||||||
use Wallabag\SiteConfig\SiteConfig;
|
use Wallabag\SiteConfig\SiteConfig;
|
||||||
use Wallabag\SiteConfig\SiteConfigBuilder;
|
use Wallabag\SiteConfig\SiteConfigBuilder;
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ class AuthenticatorSubscriber implements SubscriberInterface, LoggerAwareInterfa
|
||||||
/** @var SiteConfigBuilder */
|
/** @var SiteConfigBuilder */
|
||||||
private $configBuilder;
|
private $configBuilder;
|
||||||
|
|
||||||
/** @var Authenticator */
|
/** @var LoginFormAuthenticator */
|
||||||
private $authenticator;
|
private $authenticator;
|
||||||
|
|
||||||
/** @var LoggerInterface */
|
/** @var LoggerInterface */
|
||||||
|
@ -32,7 +32,7 @@ class AuthenticatorSubscriber implements SubscriberInterface, LoggerAwareInterfa
|
||||||
/**
|
/**
|
||||||
* AuthenticatorSubscriber constructor.
|
* AuthenticatorSubscriber constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct(SiteConfigBuilder $configBuilder, Authenticator $authenticator)
|
public function __construct(SiteConfigBuilder $configBuilder, LoginFormAuthenticator $authenticator)
|
||||||
{
|
{
|
||||||
$this->configBuilder = $configBuilder;
|
$this->configBuilder = $configBuilder;
|
||||||
$this->authenticator = $authenticator;
|
$this->authenticator = $authenticator;
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Wallabag\SiteConfig\Authenticator;
|
|
||||||
|
|
||||||
use GuzzleHttp\ClientInterface;
|
|
||||||
use Wallabag\SiteConfig\SiteConfig;
|
|
||||||
|
|
||||||
interface Authenticator
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Logs the configured user on the given Guzzle client.
|
|
||||||
*
|
|
||||||
* @return self
|
|
||||||
*/
|
|
||||||
public function login(SiteConfig $siteConfig, ClientInterface $guzzle);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if we are logged into the site, but without calling the server (e.g. do we have a Cookie).
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isLoggedIn(SiteConfig $siteConfig, ClientInterface $guzzle);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks from the HTML of a page if authentication is requested by a grabbed page.
|
|
||||||
*
|
|
||||||
* @param string $html
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isLoginRequired(SiteConfig $siteConfig, $html);
|
|
||||||
}
|
|
|
@ -9,8 +9,13 @@ use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
|
||||||
use Wallabag\ExpressionLanguage\AuthenticatorProvider;
|
use Wallabag\ExpressionLanguage\AuthenticatorProvider;
|
||||||
use Wallabag\SiteConfig\SiteConfig;
|
use Wallabag\SiteConfig\SiteConfig;
|
||||||
|
|
||||||
class LoginFormAuthenticator implements Authenticator
|
class LoginFormAuthenticator
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Logs the configured user on the given Guzzle client.
|
||||||
|
*
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
public function login(SiteConfig $siteConfig, ClientInterface $guzzle)
|
public function login(SiteConfig $siteConfig, ClientInterface $guzzle)
|
||||||
{
|
{
|
||||||
$postFields = [
|
$postFields = [
|
||||||
|
@ -26,6 +31,11 @@ class LoginFormAuthenticator implements Authenticator
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if we are logged into the site, but without calling the server (e.g. do we have a Cookie).
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
public function isLoggedIn(SiteConfig $siteConfig, ClientInterface $guzzle)
|
public function isLoggedIn(SiteConfig $siteConfig, ClientInterface $guzzle)
|
||||||
{
|
{
|
||||||
if (($cookieJar = $guzzle->getDefaultOption('cookies')) instanceof CookieJar) {
|
if (($cookieJar = $guzzle->getDefaultOption('cookies')) instanceof CookieJar) {
|
||||||
|
@ -41,6 +51,13 @@ class LoginFormAuthenticator implements Authenticator
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks from the HTML of a page if authentication is requested by a grabbed page.
|
||||||
|
*
|
||||||
|
* @param string $html
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
public function isLoginRequired(SiteConfig $siteConfig, $html)
|
public function isLoginRequired(SiteConfig $siteConfig, $html)
|
||||||
{
|
{
|
||||||
// need to check for the login dom element ($options['not_logged_in_xpath']) in the HTML
|
// need to check for the login dom element ($options['not_logged_in_xpath']) in the HTML
|
||||||
|
|
|
@ -14,13 +14,13 @@ use Monolog\Logger;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Wallabag\Guzzle\AuthenticatorSubscriber;
|
use Wallabag\Guzzle\AuthenticatorSubscriber;
|
||||||
use Wallabag\SiteConfig\ArraySiteConfigBuilder;
|
use Wallabag\SiteConfig\ArraySiteConfigBuilder;
|
||||||
use Wallabag\SiteConfig\Authenticator\Authenticator;
|
use Wallabag\SiteConfig\Authenticator\LoginFormAuthenticator;
|
||||||
|
|
||||||
class AuthenticatorSubscriberTest extends TestCase
|
class AuthenticatorSubscriberTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testGetEvents()
|
public function testGetEvents()
|
||||||
{
|
{
|
||||||
$authenticator = $this->getMockBuilder(Authenticator::class)
|
$authenticator = $this->getMockBuilder(LoginFormAuthenticator::class)
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ class AuthenticatorSubscriberTest extends TestCase
|
||||||
|
|
||||||
public function testLoginIfRequiredNotRequired()
|
public function testLoginIfRequiredNotRequired()
|
||||||
{
|
{
|
||||||
$authenticator = $this->getMockBuilder(Authenticator::class)
|
$authenticator = $this->getMockBuilder(LoginFormAuthenticator::class)
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ class AuthenticatorSubscriberTest extends TestCase
|
||||||
|
|
||||||
public function testLoginIfRequiredWithNotLoggedInUser()
|
public function testLoginIfRequiredWithNotLoggedInUser()
|
||||||
{
|
{
|
||||||
$authenticator = $this->getMockBuilder(Authenticator::class)
|
$authenticator = $this->getMockBuilder(LoginFormAuthenticator::class)
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ class AuthenticatorSubscriberTest extends TestCase
|
||||||
|
|
||||||
public function testLoginIfRequestedNotRequired()
|
public function testLoginIfRequestedNotRequired()
|
||||||
{
|
{
|
||||||
$authenticator = $this->getMockBuilder(Authenticator::class)
|
$authenticator = $this->getMockBuilder(LoginFormAuthenticator::class)
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ class AuthenticatorSubscriberTest extends TestCase
|
||||||
|
|
||||||
public function testLoginIfRequestedNotRequested()
|
public function testLoginIfRequestedNotRequested()
|
||||||
{
|
{
|
||||||
$authenticator = $this->getMockBuilder(Authenticator::class)
|
$authenticator = $this->getMockBuilder(LoginFormAuthenticator::class)
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ class AuthenticatorSubscriberTest extends TestCase
|
||||||
|
|
||||||
public function testLoginIfRequestedRequested()
|
public function testLoginIfRequestedRequested()
|
||||||
{
|
{
|
||||||
$authenticator = $this->getMockBuilder(Authenticator::class)
|
$authenticator = $this->getMockBuilder(LoginFormAuthenticator::class)
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
|
@ -263,7 +263,7 @@ class AuthenticatorSubscriberTest extends TestCase
|
||||||
|
|
||||||
public function testLoginIfRequestedRedirect()
|
public function testLoginIfRequestedRedirect()
|
||||||
{
|
{
|
||||||
$authenticator = $this->getMockBuilder(Authenticator::class)
|
$authenticator = $this->getMockBuilder(LoginFormAuthenticator::class)
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue