aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Identity/OAuth2Storage.php
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2018-08-12 14:03:36 +0200
committerMario <mario@mariovavti.com>2018-08-12 14:03:36 +0200
commit26f51ece9081e3994fd591906b5ccc608cfbf709 (patch)
tree2301c291a1d673bab9e42912c1c15efe7d0db07b /Zotlabs/Identity/OAuth2Storage.php
parent5ff0f09a4509955dede91fdb38711e1c389c9ae4 (diff)
parent0b31c677f253907ee9a36e12ae51763b2d69a574 (diff)
downloadvolse-hubzilla-26f51ece9081e3994fd591906b5ccc608cfbf709.tar.gz
volse-hubzilla-26f51ece9081e3994fd591906b5ccc608cfbf709.tar.bz2
volse-hubzilla-26f51ece9081e3994fd591906b5ccc608cfbf709.zip
Merge branch 'oauth2' into 'dev'
Fixes to OAuth2 connect-with-openid. Add zothash Claim. Add zotwebbie Claim. See merge request hubzilla/core!1254
Diffstat (limited to 'Zotlabs/Identity/OAuth2Storage.php')
-rw-r--r--Zotlabs/Identity/OAuth2Storage.php51
1 files changed, 49 insertions, 2 deletions
diff --git a/Zotlabs/Identity/OAuth2Storage.php b/Zotlabs/Identity/OAuth2Storage.php
index bc6db565c..a50b21a70 100644
--- a/Zotlabs/Identity/OAuth2Storage.php
+++ b/Zotlabs/Identity/OAuth2Storage.php
@@ -50,20 +50,67 @@ class OAuth2Storage extends \OAuth2\Storage\Pdo {
public function getUser($username)
{
- $x = channelx_by_nick($username);
+ $x = channelx_by_n($username);
if(! $x) {
return false;
}
return( [
+ 'webbie' => $x['channel_address'].'@'.\App::get_hostname(),
+ 'zothash' => $x['channel_hash'],
'username' => $x['channel_address'],
'user_id' => $x['channel_id'],
+ 'name' => $x['channel_name'],
'firstName' => $x['channel_name'],
'lastName' => '',
'password' => 'NotARealPassword'
] );
}
+ public function scopeExists($scope) {
+ // Report that the scope is valid even if it's not.
+ // We will only return a very small subset no matter what.
+ // @TODO: Truly validate the scope
+ // see vendor/bshaffer/oauth2-server-php/src/OAuth2/Storage/ScopeInterface.php and
+ // vendor/bshaffer/oauth2-server-php/src/OAuth2/Storage/Pdo.php
+ // for more info.
+ return true;
+ }
+
+ public function getDefaultScope($client_id=null) {
+ // Do not REQUIRE a scope
+ // see vendor/bshaffer/oauth2-server-php/src/OAuth2/Storage/ScopeInterface.php and
+ // for more info.
+ return null;
+ }
+
+ public function getUserClaims ($user_id, $claims) {
+ // Populate the CLAIMS requested (if any).
+ // @TODO: create a more reasonable/comprehensive list.
+ // @TODO: present claims on the AUTHORIZATION screen
+
+ $userClaims = Array();
+ $claims = explode (' ', trim($claims));
+ $validclaims = Array ("name","preferred_username","zothash");
+ $claimsmap = Array (
+ "zotwebbie" => 'webbie',
+ "zothash" => 'zothash',
+ "name" => 'name',
+ "preferred_username" => "username"
+ );
+ $userinfo = $this->getUser($user_id);
+ foreach ($validclaims as $validclaim) {
+ if (in_array($validclaim,$claims)) {
+ $claimkey = $claimsmap[$validclaim];
+ $userClaims[$validclaim] = $userinfo[$claimkey];
+ } else {
+ $userClaims[$validclaim] = $validclaim;
+ }
+ }
+ $userClaims["sub"]=$user_id;
+ return $userClaims;
+ }
+
/**
* plaintext passwords are bad! Override this for your application
*
@@ -78,4 +125,4 @@ class OAuth2Storage extends \OAuth2\Storage\Pdo {
return true;
}
-} \ No newline at end of file
+}