[feature/oauth] Scopes/path part one

PHPBB3-11673
This commit is contained in:
Joseph Warner 2013-07-14 11:38:19 -04:00
parent a7bfe5eeeb
commit e600596602

View file

@ -125,12 +125,20 @@ class phpbb_auth_provider_oauth extends phpbb_auth_provider_base
} }
$storage = new phpbb_auth_oauth_token_storage($this->db, $this->user, $service_name, $this->auth_provider_oauth_table); $storage = new phpbb_auth_oauth_token_storage($this->db, $this->user, $service_name, $this->auth_provider_oauth_table);
$service = $this->get_service($service_name, $storage, $service_credentials, $this->get_scopes($service_name));
if ($this->request->is_set('code', phpbb_request_interface::GET)) if ($this->request->is_set('code', phpbb_request_interface::GET))
{ {
// Second pass: request access token, authenticate with phpBB // This was a callback request from the service provider
$service->requestAccessToken( $_GET['code'] );
// Send a request with it
$result = json_decode( $service->request('user/info'), true );
} else { } else {
// First pass: get authorization uri, redirect to service $url = $service->getAuthorizationUri();
// TODO: modify $url for the appropriate return points
header('Location: ' . $url);
} }
} }
@ -206,4 +214,53 @@ class phpbb_auth_provider_oauth extends phpbb_auth_provider_base
return $this->service[$service_name]; return $this->service[$service_name];
} }
/**
* Returns the scopes of the service required for authentication
*
* @param string $service_name
* @return array An array of the scopes required from the service
*/
protected function get_scopes($service_name)
{
$scopes = array();
switch ($service_name)
{
case 'GitHub':
$scopes[] = 'user';
break;
case 'google':
$scopes[] = 'userinfo_email';
$scopes[] = 'userinfo_profile';
break;
case 'instagram':
case 'microsoft':
$scopes[] = 'basic';
break;
case 'linkedin':
$scopes[] = 'r_basicprofile';
break;
}
return $scopes;
}
/**
* Returns the path desired of the service
*
* @param string $service_name
* @return string|UriInterface
*/
protected function get_path($service_name)
{
switch ($service_name)
{
default:
$path = '';
break;
}
return $path;
}
} }