1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-29 18:50:25 +02:00

[feature/oauth] Works in all tests now

PHPBB3-11673
This commit is contained in:
Joseph Warner 2013-07-29 16:03:54 -04:00
parent 641433920e
commit 3d55e5faa9
3 changed files with 36 additions and 11 deletions

View File

@ -59,11 +59,19 @@ class ucp_login_link
{ {
if ($request->is_set_post('login')) if ($request->is_set_post('login'))
{ {
$login_username = $request->variable('login_username', '', false, phpbb_request_interface::POST);
$login_password = $request->untrimmed_variable('login_password', '', true, phpbb_request_interface::POST);
$login_result = $auth_provider->login($login_username, $login_password);
// We only care if there is or is not an error // We only care if there is or is not an error
$login_error = $this->perform_login_action(); $login_error = $this->process_login_result($login_result);
if (!$login_error) if (!$login_error)
{ {
// Give the user_id to the data
$data['user_id'] = $login_result['user_row']['user_id'];
// The user is now logged in, attempt to link the user to the external account // The user is now logged in, attempt to link the user to the external account
$result = $auth_provider->link_account($data); $result = $auth_provider->link_account($data);
@ -71,6 +79,9 @@ class ucp_login_link
{ {
$login_link_error = $user->lang[$result]; $login_link_error = $user->lang[$result];
} else { } else {
// Finish login
$result = $user->session_create($login_result['user_row']['user_id'], false, false, true);
// Perform a redirect as the account has been linked // Perform a redirect as the account has been linked
$this->perform_redirect(); $this->perform_redirect();
} }
@ -117,13 +128,9 @@ class ucp_login_link
return $login_link_data; return $login_link_data;
} }
protected function perform_login_action() protected function process_login_result($result)
{ {
global $auth, $config, $request, $template, $user; global $config, $request, $template, $user;
$login_username = $request->variable('login_username', '', false, phpbb_request_interface::POST);
$login_password = $request->untrimmed_variable('login_password', '', true, phpbb_request_interface::POST);
$result = $auth->login($login_username, $login_password);
$login_error = null; $login_error = null;

View File

@ -394,15 +394,15 @@ class phpbb_auth_provider_oauth extends phpbb_auth_provider_base
$this->current_uri->setQuery('mode=login_link&login_link_oauth_service=' . $service_name); $this->current_uri->setQuery('mode=login_link&login_link_oauth_service=' . $service_name);
$service_credentials = $this->service_providers[$service_name]->get_service_credentials(); $service_credentials = $this->service_providers[$service_name]->get_service_credentials();
$scopes = $this->service_providers[$service_name]->get_auth_scope(); $scopes = $this->service_providers[$service_name]->get_auth_scope();
$service = $this->get_service($service_name, $storage, $service_credentials, $scopes); $service = $this->get_service(strtolower($link_data['oauth_service']), $storage, $service_credentials, $scopes);
$this->service_providers[$service_name]->set_external_service_provider($service); $this->service_providers[$service_name]->set_external_service_provider($service);
// The user has already authenticated successfully, request to authenticate again // The user has already authenticated successfully, request to authenticate again
$unique_id = $this->service_providers[$service_name]->perform_auth_login(); $unique_id = $this->service_providers[$service_name]->perform_auth_link();
// Insert into table, they will be able to log in after this // Insert into table, they will be able to log in after this
$data = array( $data = array(
'user_id' => $this->user->data['user_id'], 'user_id' => $link_data['user_id'],
'provider' => strtolower($link_data['oauth_service']), 'provider' => strtolower($link_data['oauth_service']),
'oauth_provider_id' => $unique_id, 'oauth_provider_id' => $unique_id,
); );

View File

@ -81,7 +81,7 @@ class phpbb_auth_provider_oauth_service_google extends phpbb_auth_provider_oauth
throw new Exception('Invalid service provider type'); throw new Exception('Invalid service provider type');
} }
// This was a callback request from bitly, get the token // This was a callback request, get the token
$this->service_provider->requestAccessToken( $this->request->variable('code', '') ); $this->service_provider->requestAccessToken( $this->request->variable('code', '') );
// Send a request with it // Send a request with it
@ -90,4 +90,22 @@ class phpbb_auth_provider_oauth_service_google extends phpbb_auth_provider_oauth
// Return the unique identifier returned from bitly // Return the unique identifier returned from bitly
return $result['id']; return $result['id'];
} }
/**
* {@inheritdoc}
*/
public function perform_auth_link()
{
if (!($this->service_provider instanceof \OAuth\OAuth2\Service\Google))
{
// TODO: make exception class and use language constant
throw new Exception('Invalid service provider type');
}
// Send a request with it
$result = json_decode( $this->service_provider->request('https://www.googleapis.com/oauth2/v1/userinfo'), true );
// Return the unique identifier returned from bitly
return $result['id'];
}
} }