mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/12574] Remove passwords manager & container requirement from oauth
PHPBB3-12574
This commit is contained in:
parent
0cbe05faad
commit
f460194379
3 changed files with 66 additions and 54 deletions
|
@ -53,11 +53,10 @@ services:
|
||||||
class: phpbb\auth\provider\oauth\oauth
|
class: phpbb\auth\provider\oauth\oauth
|
||||||
arguments:
|
arguments:
|
||||||
- '@config'
|
- '@config'
|
||||||
- '@service_container'
|
|
||||||
- '@dbal.conn'
|
- '@dbal.conn'
|
||||||
|
- '@auth.provider.db'
|
||||||
- '@dispatcher'
|
- '@dispatcher'
|
||||||
- '@language'
|
- '@language'
|
||||||
- '@passwords.manager'
|
|
||||||
- '@request'
|
- '@request'
|
||||||
- '@auth.provider.oauth.service_collection'
|
- '@auth.provider.oauth.service_collection'
|
||||||
- '@user'
|
- '@user'
|
||||||
|
|
|
@ -13,44 +13,50 @@
|
||||||
|
|
||||||
namespace phpbb\auth\provider\oauth;
|
namespace phpbb\auth\provider\oauth;
|
||||||
|
|
||||||
|
use OAuth\Common\Http\Exception\TokenResponseException;
|
||||||
use OAuth\ServiceFactory;
|
use OAuth\ServiceFactory;
|
||||||
use OAuth\Common\Consumer\Credentials;
|
use OAuth\Common\Consumer\Credentials;
|
||||||
use OAuth\Common\Service\ServiceInterface;
|
use OAuth\Common\Service\ServiceInterface;
|
||||||
use OAuth\OAuth1\Service\AbstractService as OAuth1Service;
|
use OAuth\OAuth1\Service\AbstractService as OAuth1Service;
|
||||||
use OAuth\OAuth2\Service\AbstractService as OAuth2Service;
|
use OAuth\OAuth2\Service\AbstractService as OAuth2Service;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use phpbb\auth\provider\base;
|
||||||
|
use phpbb\auth\provider\db;
|
||||||
use phpbb\auth\provider\oauth\service\exception;
|
use phpbb\auth\provider\oauth\service\exception;
|
||||||
|
use phpbb\config\config;
|
||||||
|
use phpbb\db\driver\driver_interface;
|
||||||
|
use phpbb\di\service_collection;
|
||||||
|
use phpbb\event\dispatcher;
|
||||||
|
use phpbb\language\language;
|
||||||
|
use phpbb\request\request_interface;
|
||||||
|
use phpbb\user;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OAuth authentication provider for phpBB3
|
* OAuth authentication provider for phpBB3
|
||||||
*/
|
*/
|
||||||
class oauth extends \phpbb\auth\provider\base
|
class oauth extends base
|
||||||
{
|
{
|
||||||
/** @var \phpbb\config\config */
|
/** @var config */
|
||||||
protected $config;
|
protected $config;
|
||||||
|
|
||||||
/** @var ContainerInterface */
|
/** @var driver_interface */
|
||||||
protected $container;
|
|
||||||
|
|
||||||
/** @var \phpbb\db\driver\driver_interface */
|
|
||||||
protected $db;
|
protected $db;
|
||||||
|
|
||||||
/** @var \phpbb\event\dispatcher */
|
/** @var db */
|
||||||
|
protected $db_auth;
|
||||||
|
|
||||||
|
/** @var dispatcher */
|
||||||
protected $dispatcher;
|
protected $dispatcher;
|
||||||
|
|
||||||
/** @var \phpbb\language\language */
|
/** @var language */
|
||||||
protected $language;
|
protected $language;
|
||||||
|
|
||||||
/** @var \phpbb\passwords\manager */
|
/** @var request_interface */
|
||||||
protected $passwords_manager;
|
|
||||||
|
|
||||||
/** @var \phpbb\request\request_interface */
|
|
||||||
protected $request;
|
protected $request;
|
||||||
|
|
||||||
/** @var \phpbb\di\service_collection */
|
/** @var service_collection */
|
||||||
protected $service_providers;
|
protected $service_providers;
|
||||||
|
|
||||||
/** @var \phpbb\user */
|
/** @var user */
|
||||||
protected $user;
|
protected $user;
|
||||||
|
|
||||||
/** @var string OAuth table: token storage */
|
/** @var string OAuth table: token storage */
|
||||||
|
@ -74,15 +80,14 @@ class oauth extends \phpbb\auth\provider\base
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param \phpbb\config\config $config Config object
|
* @param config $config Config object
|
||||||
* @param ContainerInterface $container Service container object
|
* @param driver_interface $db Database object
|
||||||
* @param \phpbb\db\driver\driver_interface $db Database object
|
* @param db $db_auth DB auth provider
|
||||||
* @param \phpbb\event\dispatcher $dispatcher Event dispatcher object
|
* @param dispatcher $dispatcher Event dispatcher object
|
||||||
* @param \phpbb\language\language $language Language object
|
* @param language $language Language object
|
||||||
* @param \phpbb\passwords\manager $passwords_manager Password manager object
|
* @param request_interface $request Request object
|
||||||
* @param \phpbb\request\request_interface $request Request object
|
* @param service_collection $service_providers OAuth providers service collection
|
||||||
* @param \phpbb\di\service_collection $service_providers OAuth providers service collection
|
* @param user $user User object
|
||||||
* @param \phpbb\user $user User object
|
|
||||||
* @param string $oauth_token_table OAuth table: token storage
|
* @param string $oauth_token_table OAuth table: token storage
|
||||||
* @param string $oauth_state_table OAuth table: state
|
* @param string $oauth_state_table OAuth table: state
|
||||||
* @param string $oauth_account_table OAuth table: account association
|
* @param string $oauth_account_table OAuth table: account association
|
||||||
|
@ -91,15 +96,14 @@ class oauth extends \phpbb\auth\provider\base
|
||||||
* @param string $php_ext php File extension
|
* @param string $php_ext php File extension
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
\phpbb\config\config $config,
|
config $config,
|
||||||
ContainerInterface $container,
|
driver_interface $db,
|
||||||
\phpbb\db\driver\driver_interface $db,
|
db $db_auth,
|
||||||
\phpbb\event\dispatcher $dispatcher,
|
dispatcher $dispatcher,
|
||||||
\phpbb\language\language $language,
|
language $language,
|
||||||
\phpbb\passwords\manager $passwords_manager,
|
request_interface $request,
|
||||||
\phpbb\request\request_interface $request,
|
service_collection $service_providers,
|
||||||
\phpbb\di\service_collection $service_providers,
|
user $user,
|
||||||
\phpbb\user $user,
|
|
||||||
$oauth_token_table,
|
$oauth_token_table,
|
||||||
$oauth_state_table,
|
$oauth_state_table,
|
||||||
$oauth_account_table,
|
$oauth_account_table,
|
||||||
|
@ -109,10 +113,9 @@ class oauth extends \phpbb\auth\provider\base
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->container = $container;
|
|
||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
|
$this->db_auth = $db_auth;
|
||||||
$this->dispatcher = $dispatcher;
|
$this->dispatcher = $dispatcher;
|
||||||
$this->passwords_manager = $passwords_manager;
|
|
||||||
$this->language = $language;
|
$this->language = $language;
|
||||||
$this->service_providers = $service_providers;
|
$this->service_providers = $service_providers;
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
|
@ -153,18 +156,7 @@ class oauth extends \phpbb\auth\provider\base
|
||||||
// Temporary workaround for only having one authentication provider available
|
// Temporary workaround for only having one authentication provider available
|
||||||
if (!$this->request->is_set('oauth_service'))
|
if (!$this->request->is_set('oauth_service'))
|
||||||
{
|
{
|
||||||
$provider = new \phpbb\auth\provider\db(
|
return $this->db_auth->login($username, $password);
|
||||||
$this->db,
|
|
||||||
$this->config,
|
|
||||||
$this->passwords_manager,
|
|
||||||
$this->request,
|
|
||||||
$this->user,
|
|
||||||
$this->container,
|
|
||||||
$this->root_path,
|
|
||||||
$this->php_ext
|
|
||||||
);
|
|
||||||
|
|
||||||
return $provider->login($username, $password);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request the name of the OAuth service
|
// Request the name of the OAuth service
|
||||||
|
@ -822,10 +814,10 @@ class oauth extends \phpbb\auth\provider\base
|
||||||
switch ($service::OAUTH_VERSION)
|
switch ($service::OAUTH_VERSION)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
return $this->request->is_set('oauth_token', \phpbb\request\request_interface::GET);
|
return $this->request->is_set('oauth_token', request_interface::GET);
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
return $this->request->is_set('code', \phpbb\request\request_interface::GET);
|
return $this->request->is_set('code', request_interface::GET);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
@ -850,7 +842,7 @@ class oauth extends \phpbb\auth\provider\base
|
||||||
$token = $service->requestRequestToken();
|
$token = $service->requestRequestToken();
|
||||||
$parameters = ['oauth_token' => $token->getRequestToken()];
|
$parameters = ['oauth_token' => $token->getRequestToken()];
|
||||||
}
|
}
|
||||||
catch (\OAuth\Common\Http\Exception\TokenResponseException $e)
|
catch (TokenResponseException $e)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'status' => LOGIN_ERROR_EXTERNAL_AUTH,
|
'status' => LOGIN_ERROR_EXTERNAL_AUTH,
|
||||||
|
|
|
@ -60,13 +60,34 @@ class phpbb_functions_user_delete_test extends phpbb_database_test_case
|
||||||
// Set up passwords manager
|
// Set up passwords manager
|
||||||
$passwords_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, array_keys($passwords_drivers));
|
$passwords_manager = new \phpbb\passwords\manager($config, $passwords_drivers, $passwords_helper, array_keys($passwords_drivers));
|
||||||
|
|
||||||
|
$plugins = new \phpbb\di\service_collection($phpbb_container);
|
||||||
|
$plugins->add('core.captcha.plugins.nogd');
|
||||||
|
$phpbb_container->set(
|
||||||
|
'captcha.factory',
|
||||||
|
new \phpbb\captcha\factory($phpbb_container, $plugins)
|
||||||
|
);
|
||||||
|
$phpbb_container->set(
|
||||||
|
'core.captcha.plugins.nogd',
|
||||||
|
new \phpbb\captcha\plugins\nogd()
|
||||||
|
);
|
||||||
|
// Set up passwords manager
|
||||||
|
$db_auth_provider = new \phpbb\auth\provider\db(
|
||||||
|
new \phpbb\captcha\factory($phpbb_container, $plugins),
|
||||||
|
$config,
|
||||||
|
$db,
|
||||||
|
$passwords_manager,
|
||||||
|
$request,
|
||||||
|
$user,
|
||||||
|
$phpbb_root_path,
|
||||||
|
$phpEx
|
||||||
|
);
|
||||||
|
|
||||||
$oauth_provider = new \phpbb\auth\provider\oauth\oauth(
|
$oauth_provider = new \phpbb\auth\provider\oauth\oauth(
|
||||||
$config,
|
$config,
|
||||||
$phpbb_container,
|
|
||||||
$db,
|
$db,
|
||||||
|
$db_auth_provider,
|
||||||
$phpbb_dispatcher,
|
$phpbb_dispatcher,
|
||||||
$lang,
|
$lang,
|
||||||
$passwords_manager,
|
|
||||||
$request,
|
$request,
|
||||||
$oauth_provider_collection,
|
$oauth_provider_collection,
|
||||||
$user,
|
$user,
|
||||||
|
|
Loading…
Add table
Reference in a new issue