aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phpBB/includes/auth/provider/oauth.php95
1 files changed, 70 insertions, 25 deletions
diff --git a/phpBB/includes/auth/provider/oauth.php b/phpBB/includes/auth/provider/oauth.php
index 4cf9749b36..cdfcace5b2 100644
--- a/phpBB/includes/auth/provider/oauth.php
+++ b/phpBB/includes/auth/provider/oauth.php
@@ -61,6 +61,20 @@ class phpbb_auth_provider_oauth extends phpbb_auth_provider_base
protected $driver;
/**
+ * Cached service once it has been created
+ *
+ * @var \OAuth\Common\Service\ServiceInterface|null
+ */
+ protected $service;
+
+ /**
+ * Cached current uri object
+ *
+ * @var \OAuth\Common\Http\Uri\UriInterface|null
+ */
+ protected $current_uri;
+
+ /**
* OAuth Authentication Constructor
*
* @param phpbb_db_driver $db
@@ -84,8 +98,8 @@ class phpbb_auth_provider_oauth extends phpbb_auth_provider_base
public function login($username, $password)
{
// Requst the name of the OAuth service
- $service = $this->request->variable('oauth_service', '', false, phpbb_request_interface::POST);
- if ($service === '')
+ $service_name = $this->request->variable('oauth_service', '', false, phpbb_request_interface::POST);
+ if ($service_name === '')
{
return array(
'status' => LOGIN_ERROR_EXTERNAL_AUTH,
@@ -94,8 +108,56 @@ class phpbb_auth_provider_oauth extends phpbb_auth_provider_base
);
}
+ if ($this->request->is_set('code', phpbb_request_interface::GET))
+ {
+ // Second pass: request access token, authenticate with phpBB
+ } else {
+ // First pass: get authorization uri, redirect to service
+ }
+ }
+
+ /**
+ *
+ */
+ protected function get_service_credentials($service_name)
+ {
+ return array(
+ 'key' => $this->config['auth_oauth_' . $service_name . '_key'],
+ 'secret' => $this->config['auth_oauth_' . $service_name . '_secret'],
+ );
+ }
+
+ protected function get_current_uri()
+ {
+ if ($this->current_uri)
+ {
+ return $this->current_uri;
+ }
+
+ $uri_factory = new \OAuth\Common\Http\Uri\UriFactory();
+ $current_uri = $uri_factory->createFromSuperGlobalArray($this->request->get_super_global(phpbb_request_interface::SERVER));
+ $current_uri->setQuery('');
+
+ $this->current_uri = $current_uri;
+ return $current_uri;
+ }
+
+ /**
+ * Returns the cached service object or creates a new one
+ *
+ * @param string $service_name The name of the service
+ * @param array $scope The scope of the request against the api.
+ * @return \OAuth\Common\Service\ServiceInterface
+ */
+ protected function get_service($service_name, array $scopes = array())
+ {
+ if ($this->service)
+ {
+ return $this->service;
+ }
+
// Get the service credentials for the given service
- $service_credentials = $this->get_credentials($service);
+ $service_credentials = $this->get_credentials($service_name);
// Check that the service has settings
if ($service_credentials['key'] == false || $service_credentials['secret'] == false)
@@ -107,14 +169,10 @@ class phpbb_auth_provider_oauth extends phpbb_auth_provider_base
);
}
- $service_factory = new \OAuth\ServiceFactory();
- $uri_factory = new \OAuth\Common\Http\Uri\UriFactory();
- $current_uri = $uri_factory->createFromSuperGlobalArray($this->request->get_super_global(phpbb_request_interface::SERVER));
- $current_uri->setQuery('');
-
- // In-memory storage
$storage = new phpbb_auth_oauth_token_storage($this->driver);
+ $current_uri = $this->get_current_uri();
+
// Setup the credentials for the requests
$credentials = new Credentials(
$service_credentials['key'],
@@ -122,22 +180,9 @@ class phpbb_auth_provider_oauth extends phpbb_auth_provider_base
$current_uri->getAbsoluteUri()
);
- if ($this->request->is_set('code', phpbb_request_interface::GET))
- {
- // Second pass: request access token, authenticate with phpBB
- } else {
- // First pass: get authorization uri, redirect to service
- }
- }
+ $service_factory = new \OAuth\ServiceFactory();
+ $this->service = $service_factory->createService($service_name, $credentials, $storage, $scopes);
- /**
- *
- */
- protected function get_service_credentials($service)
- {
- return array(
- 'key' => $this->config['auth_oauth_' . $service . '_key'],
- 'secret' => $this->config['auth_oauth_' . $service . '_secret'],
- );
+ return $this->service;
}
}