From 24bf333e161332ddd589831228e35ad9eb1e8f18 Mon Sep 17 00:00:00 2001 From: Joseph Warner Date: Sat, 13 Jul 2013 16:51:38 -0400 Subject: [PATCH] [feature/oauth] Use DB for OAuth token storage PHPBB3-11673 --- phpBB/config/auth_providers.yml | 1 - phpBB/develop/create_schema_files.php | 9 ++++ phpBB/includes/auth/oauth/token_storage.php | 18 +++++--- phpBB/includes/auth/provider/oauth.php | 13 +----- .../data/310/auth_provider_oauth.php | 42 +++++++++++++++++++ 5 files changed, 66 insertions(+), 17 deletions(-) create mode 100644 phpBB/includes/db/migration/data/310/auth_provider_oauth.php diff --git a/phpBB/config/auth_providers.yml b/phpBB/config/auth_providers.yml index 78c799ffb1..4d402e71f2 100644 --- a/phpBB/config/auth_providers.yml +++ b/phpBB/config/auth_providers.yml @@ -42,6 +42,5 @@ services: - @config - @request - @user - - @cache.driver tags: - { name: auth.provider } diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php index 316fbe19e6..f3eeb31c28 100644 --- a/phpBB/develop/create_schema_files.php +++ b/phpBB/develop/create_schema_files.php @@ -923,6 +923,15 @@ function get_schema_struct() ), ); + $schemda_data['auth_provider_oauth'] = array( + 'COLUMNS' => array( + 'user_id' => array('UINT', 0), // phpbb_users.user_id + 'oauth_provider' => array('VCHAR'), // Name of the OAuth provider + 'oauth_token' => array('TEXT_UNI'), // Serialized token + ), + 'PRIMARY_KEY' => array('user_id', 'oauth_provider'), + ); + $schema_data['phpbb_banlist'] = array( 'COLUMNS' => array( 'ban_id' => array('UINT', NULL, 'auto_increment'), diff --git a/phpBB/includes/auth/oauth/token_storage.php b/phpBB/includes/auth/oauth/token_storage.php index 2d3c58d25a..b658333900 100644 --- a/phpBB/includes/auth/oauth/token_storage.php +++ b/phpBB/includes/auth/oauth/token_storage.php @@ -28,9 +28,16 @@ class phpbb_auth_oauth_token_storage implements TokenStorageInterface /** * Cache driver. * - * @var phpbb_cache_driver_interface + * @var phpbb_db_driver */ - protected $driver; + protected $db; + + /** + * Name of the OAuth provider + * + * @var string + */ + protected $service_name; /** * @var object|TokenInterface @@ -40,11 +47,12 @@ class phpbb_auth_oauth_token_storage implements TokenStorageInterface /** * Creates token storage for phpBB. * - * @param phpbb_cache_driver_interface $driver The cache driver + * @param phpbb_db_driver $db */ - public function __construct(phpbb_cache_driver_interface $driver) + public function __construct(phpbb_db_driver $db, $service_name) { - $this->driver = $driver; + $this->db = $db; + $this->service_name = $service_name; } /** diff --git a/phpBB/includes/auth/provider/oauth.php b/phpBB/includes/auth/provider/oauth.php index 267105e6b6..55a12211d6 100644 --- a/phpBB/includes/auth/provider/oauth.php +++ b/phpBB/includes/auth/provider/oauth.php @@ -53,13 +53,6 @@ class phpbb_auth_provider_oauth extends phpbb_auth_provider_base */ protected $user; - /** - * Cache driver. - * - * @var phpbb_cache_driver_interface - */ - protected $driver; - /** * Cached service once it has been created * @@ -81,15 +74,13 @@ class phpbb_auth_provider_oauth extends phpbb_auth_provider_base * @param phpbb_config $config * @param phpbb_request $request * @param phpbb_user $user - * @param phpbb_cache_driver_interface $driver */ - public function __construct(phpbb_db_driver $db, phpbb_config $config, phpbb_request $request, phpbb_user $user, phpbb_cache_driver_interface $driver) + public function __construct(phpbb_db_driver $db, phpbb_config $config, phpbb_request $request, phpbb_user $user) { $this->db = $db; $this->config = $config; $this->request = $request; $this->user = $user; - $this->driver = $driver; } /** @@ -186,7 +177,7 @@ class phpbb_auth_provider_oauth extends phpbb_auth_provider_base return $this->service; } - $storage = new phpbb_auth_oauth_token_storage($this->driver); + $storage = new phpbb_auth_oauth_token_storage($this->db, $service_name); $current_uri = $this->get_current_uri(); diff --git a/phpBB/includes/db/migration/data/310/auth_provider_oauth.php b/phpBB/includes/db/migration/data/310/auth_provider_oauth.php new file mode 100644 index 0000000000..6239cf97bc --- /dev/null +++ b/phpBB/includes/db/migration/data/310/auth_provider_oauth.php @@ -0,0 +1,42 @@ +db_tools->sql_table_exists($this->table_prefix . 'auth_provider_oauth'); + } + + public function update_schema() + { + return array( + 'add_tables' => array( + $this->table_prefix . 'auth_provider_oauth' => array( + 'COLUMNS' => array( + 'user_id' => array('UINT', 0), // phpbb_users.user_id + 'oauth_provider' => array('VCHAR'), // Name of the OAuth provider + 'oauth_token' => array('TEXT_UNI'), // Serialized token + ), + 'PRIMARY_KEY' => array('user_id', 'oauth_provider'), + ), + ), + + ); + } + + public function revert_schema() + { + return array( + 'drop_tables' => array( + $this->table_prefix . 'auth_provider_oauth', + ), + ); + } +}