aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
authorJoseph Warner <hardolaf@hardolaf.com>2013-07-14 11:38:19 -0400
committerJoseph Warner <hardolaf@hardolaf.com>2013-07-14 14:22:43 -0400
commite600596602d1fed7eedda02c848db9012fda43fa (patch)
tree955a58570b3d5502162bcb1872f4445ea9e9d425 /phpBB/includes
parenta7bfe5eeeb1250c96fb2ddb1ee19f1babe72fe3d (diff)
downloadforums-e600596602d1fed7eedda02c848db9012fda43fa.tar
forums-e600596602d1fed7eedda02c848db9012fda43fa.tar.gz
forums-e600596602d1fed7eedda02c848db9012fda43fa.tar.bz2
forums-e600596602d1fed7eedda02c848db9012fda43fa.tar.xz
forums-e600596602d1fed7eedda02c848db9012fda43fa.zip
[feature/oauth] Scopes/path part one
PHPBB3-11673
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/auth/provider/oauth.php61
1 files changed, 59 insertions, 2 deletions
diff --git a/phpBB/includes/auth/provider/oauth.php b/phpBB/includes/auth/provider/oauth.php
index d405bb77b1..79a5988526 100644
--- a/phpBB/includes/auth/provider/oauth.php
+++ b/phpBB/includes/auth/provider/oauth.php
@@ -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);
+ $service = $this->get_service($service_name, $storage, $service_credentials, $this->get_scopes($service_name));
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 {
- // 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];
}
+
+ /**
+ * 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;
+ }
}