CSteipp has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/91331


Change subject: Implement OAuth hook to get userid from username
......................................................................

Implement OAuth hook to get userid from username

Implements hook from Ie17cacd68452ffea808d63b3d5b74078577c75be

Change-Id: Ib29dbb32e1e43c24416f2b2149f147248fea074b
---
M CentralAuth.php
M CentralAuthHooks.php
2 files changed, 28 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralAuth 
refs/changes/31/91331/1

diff --git a/CentralAuth.php b/CentralAuth.php
index c860ba0..3f08459 100644
--- a/CentralAuth.php
+++ b/CentralAuth.php
@@ -295,6 +295,7 @@
 // For OAuth
 $wgHooks['OAuthGetLocalUserFromCentralId'][] = 
'CentralAuthHooks::onOAuthGetLocalUserFromCentralId';
 $wgHooks['OAuthGetCentralIdFromLocalUser'][] = 
'CentralAuthHooks::onOAuthGetCentralIdFromLocalUser';
+$wgHooks['OAuthGetCentralIdFromUserName'][] = 
'CentralAuthHooks::onOAuthGetCentralIdFromUserName';
 $wgHooks['OAuthGetUserNamesFromCentralIds'][] = 
'CentralAuthHooks::onOAuthGetUserNamesFromCentralIds';
 
 $wgAvailableRights[] = 'centralauth-merge';
diff --git a/CentralAuthHooks.php b/CentralAuthHooks.php
index fa00734..4bb1975 100644
--- a/CentralAuthHooks.php
+++ b/CentralAuthHooks.php
@@ -1491,4 +1491,31 @@
                $id = $centralUser->getId();
                return true;
        }
+
+       /**
+        * Get the username for the CentralAuth user that is also attached on 
the
+        * the OAuth central wiki. False if the username isn't for a global 
account,
+        * or that username isn't attached on the OAuth central wiki.
+        * @param string $username the username
+        * @param string $wgMWOAuthCentralWiki
+        * @param int &$id the user_id of the matching name on the central wiki
+        * @param string $wgMWOAuthSharedUserSource the authoritative extension
+        */
+       public static function onOAuthGetCentralIdFromUserName( $username, 
$wgMWOAuthCentralWiki, &$id, $wgMWOAuthSharedUserSource ) {
+               if ( $wgMWOAuthSharedUserSource !== 'CentralAuth' ) {
+                       // We aren't supposed to handle this
+                       return true;
+               }
+               $centralUser = new CentralAuthUser( $username );
+               if ( $centralUser->getId() == 0
+                       || !$centralUser->isAttached()
+                       || !$centralUser->attachedOn( $wgMWOAuthCentralWiki )
+               ) {
+                       $id = false;
+                       return false;
+               }
+
+               $id = $centralUser->getId();
+               return true;
+       }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/91331
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib29dbb32e1e43c24416f2b2149f147248fea074b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralAuth
Gerrit-Branch: master
Gerrit-Owner: CSteipp <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to