|
|
@ -15,7 +15,6 @@ use Title;
|
|
|
|
use SpecialPage;
|
|
|
|
use SpecialPage;
|
|
|
|
use Sanitizer;
|
|
|
|
use Sanitizer;
|
|
|
|
use RequestContext;
|
|
|
|
use RequestContext;
|
|
|
|
use WebRequest;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class IsekaiOIDCAuth extends AbstractPrimaryAuthenticationProvider {
|
|
|
|
class IsekaiOIDCAuth extends AbstractPrimaryAuthenticationProvider {
|
|
|
|
|
|
|
|
|
|
|
@ -88,12 +87,7 @@ class IsekaiOIDCAuth extends AbstractPrimaryAuthenticationProvider {
|
|
|
|
$GLOBALS['wgIsekaiOIDCRemember'] = true;
|
|
|
|
$GLOBALS['wgIsekaiOIDCRemember'] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( method_exists( MediaWikiServices::class, 'getAuthManager' ) ) {
|
|
|
|
$authManager = MediaWikiServices::getInstance()->getAuthManager();
|
|
|
|
// MediaWiki 1.35+
|
|
|
|
|
|
|
|
$authManager = MediaWikiServices::getInstance()->getAuthManager();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$authManager = AuthManager::singleton();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$request = RequestContext::getMain()->getRequest();
|
|
|
|
$request = RequestContext::getMain()->getRequest();
|
|
|
|
$session = $request->getSession();
|
|
|
|
$session = $request->getSession();
|
|
|
|
$session->clear('AuthManager::AutoCreateBlacklist'); // 防止缓存检测
|
|
|
|
$session->clear('AuthManager::AutoCreateBlacklist'); // 防止缓存检测
|
|
|
@ -308,22 +302,17 @@ class IsekaiOIDCAuth extends AbstractPrimaryAuthenticationProvider {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static function updateUserInfo($user, $data = null) {
|
|
|
|
public static function updateUserInfo($user, $data = null) {
|
|
|
|
if (is_string($user)) {
|
|
|
|
if (is_string($user)) {
|
|
|
|
$user = User::newFromName($user);
|
|
|
|
$user = MediaWikiServices::getInstance()->getUserFactory()->newFromName($user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($data) {
|
|
|
|
if ($data) {
|
|
|
|
$accessToken = isset($data['accessToken']) ? $data['accessToken'] : null;
|
|
|
|
$accessToken = $data['accessToken'] ?? null;
|
|
|
|
$refreshToken = isset($data['refreshToken']) ? $data['refreshToken'] : null;
|
|
|
|
$refreshToken = $data['refreshToken'] ?? null;
|
|
|
|
$newEmail = isset($data['email']) ? $data['email'] : null;
|
|
|
|
$newEmail = $data['email'] ?? null;
|
|
|
|
$newRealName = isset($data['realname']) ? $data['realname'] : null;
|
|
|
|
$newRealName = $data['realname'] ?? null;
|
|
|
|
$newPhone = isset($data['phone']) ? $data['phone'] : null;
|
|
|
|
$newPhone = $data['phone'] ?? null;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if ( method_exists( MediaWikiServices::class, 'getAuthManager' ) ) {
|
|
|
|
$authManager = MediaWikiServices::getInstance()->getAuthManager();
|
|
|
|
// MediaWiki 1.35+
|
|
|
|
|
|
|
|
$authManager = MediaWikiServices::getInstance()->getAuthManager();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$authManager = AuthManager::singleton();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$accessToken = $authManager->getAuthenticationSessionData(self::ACCESS_TOKEN_SESSION_KEY);
|
|
|
|
$accessToken = $authManager->getAuthenticationSessionData(self::ACCESS_TOKEN_SESSION_KEY);
|
|
|
|
$refreshToken = $authManager->getAuthenticationSessionData(self::REFRESH_TOKEN_SESSION_KEY);
|
|
|
|
$refreshToken = $authManager->getAuthenticationSessionData(self::REFRESH_TOKEN_SESSION_KEY);
|
|
|
@ -340,7 +329,8 @@ class IsekaiOIDCAuth extends AbstractPrimaryAuthenticationProvider {
|
|
|
|
wfDebugLog( self::LOG_TAG,
|
|
|
|
wfDebugLog( self::LOG_TAG,
|
|
|
|
'update access token for: ' . $user->getId() . '.' .
|
|
|
|
'update access token for: ' . $user->getId() . '.' .
|
|
|
|
PHP_EOL );
|
|
|
|
PHP_EOL );
|
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
|
|
|
|
|
|
|
|
|
|
|
$dbw = MediaWikiServices::getInstance()->getDBLoadBalancer()->getMaintenanceConnectionRef( DB_PRIMARY );
|
|
|
|
$dbw->upsert(
|
|
|
|
$dbw->upsert(
|
|
|
|
self::OIDC_TABLE,
|
|
|
|
self::OIDC_TABLE,
|
|
|
|
[
|
|
|
|
[
|
|
|
@ -382,19 +372,15 @@ class IsekaiOIDCAuth extends AbstractPrimaryAuthenticationProvider {
|
|
|
|
* @param int $id user id
|
|
|
|
* @param int $id user id
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function saveExtraAttributes( $id ) {
|
|
|
|
public function saveExtraAttributes( $id ) {
|
|
|
|
if ( method_exists( MediaWikiServices::class, 'getAuthManager' ) ) {
|
|
|
|
$authManager = MediaWikiServices::getInstance()->getAuthManager();
|
|
|
|
// MediaWiki 1.35+
|
|
|
|
|
|
|
|
$authManager = MediaWikiServices::getInstance()->getAuthManager();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$authManager = AuthManager::singleton();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $this->subject === null ) {
|
|
|
|
if ( $this->subject === null ) {
|
|
|
|
$this->subject = $authManager->getAuthenticationSessionData(
|
|
|
|
$this->subject = $authManager->getAuthenticationSessionData(
|
|
|
|
self::OIDC_SUBJECT_SESSION_KEY );
|
|
|
|
self::OIDC_SUBJECT_SESSION_KEY );
|
|
|
|
$authManager->removeAuthenticationSessionData(
|
|
|
|
$authManager->removeAuthenticationSessionData(
|
|
|
|
self::OIDC_SUBJECT_SESSION_KEY );
|
|
|
|
self::OIDC_SUBJECT_SESSION_KEY );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
|
|
|
$dbw = MediaWikiServices::getInstance()->getDBLoadBalancer()->getMaintenanceConnectionRef( DB_PRIMARY );
|
|
|
|
$dbw->upsert(
|
|
|
|
$dbw->upsert(
|
|
|
|
self::OIDC_TABLE,
|
|
|
|
self::OIDC_TABLE,
|
|
|
|
[
|
|
|
|
[
|
|
|
@ -412,7 +398,7 @@ class IsekaiOIDCAuth extends AbstractPrimaryAuthenticationProvider {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static function findUser( $subject ) {
|
|
|
|
public static function findUser( $subject ) {
|
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
|
|
|
$dbr = MediaWikiServices::getInstance()->getDBLoadBalancer()->getMaintenanceConnectionRef( DB_REPLICA );
|
|
|
|
$row = $dbr->selectRow(
|
|
|
|
$row = $dbr->selectRow(
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'user',
|
|
|
|
'user',
|
|
|
@ -441,7 +427,7 @@ class IsekaiOIDCAuth extends AbstractPrimaryAuthenticationProvider {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static function findOidcDataByUserId( $userId ) {
|
|
|
|
public static function findOidcDataByUserId( $userId ) {
|
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
|
|
|
$dbr = MediaWikiServices::getInstance()->getDBLoadBalancer()->getMaintenanceConnectionRef( DB_REPLICA );
|
|
|
|
$row = $dbr->selectRow(
|
|
|
|
$row = $dbr->selectRow(
|
|
|
|
[
|
|
|
|
[
|
|
|
|
self::OIDC_TABLE
|
|
|
|
self::OIDC_TABLE
|
|
|
@ -503,7 +489,7 @@ class IsekaiOIDCAuth extends AbstractPrimaryAuthenticationProvider {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$username = $nt->getText();
|
|
|
|
$username = $nt->getText();
|
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
|
|
|
$dbr = MediaWikiServices::getInstance()->getDBLoadBalancer()->getMaintenanceConnectionRef( DB_REPLICA );
|
|
|
|
$row = $dbr->selectRow(
|
|
|
|
$row = $dbr->selectRow(
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'user',
|
|
|
|
'user',
|
|
|
@ -531,7 +517,7 @@ class IsekaiOIDCAuth extends AbstractPrimaryAuthenticationProvider {
|
|
|
|
private static function getMigratedIdByEmail( $email ) {
|
|
|
|
private static function getMigratedIdByEmail( $email ) {
|
|
|
|
wfDebugLog( self::LOG_TAG, 'Matching user to email ' . $email . '.' .
|
|
|
|
wfDebugLog( self::LOG_TAG, 'Matching user to email ' . $email . '.' .
|
|
|
|
PHP_EOL );
|
|
|
|
PHP_EOL );
|
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
|
|
|
$dbr = MediaWikiServices::getInstance()->getDBLoadBalancer()->getMaintenanceConnectionRef( DB_REPLICA );
|
|
|
|
$row = $dbr->selectRow(
|
|
|
|
$row = $dbr->selectRow(
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'user',
|
|
|
|
'user',
|
|
|
@ -565,19 +551,25 @@ class IsekaiOIDCAuth extends AbstractPrimaryAuthenticationProvider {
|
|
|
|
$preferred_username = 'User';
|
|
|
|
$preferred_username = 'User';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( User::idFromName( $preferred_username ) === null ) {
|
|
|
|
if ( MediaWikiServices::getInstance()
|
|
|
|
|
|
|
|
->getUserIdentityLookup()
|
|
|
|
|
|
|
|
->getUserIdentityByName( $preferred_username ) ) {
|
|
|
|
|
|
|
|
|
|
|
|
return $preferred_username;
|
|
|
|
return $preferred_username;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$count = 1;
|
|
|
|
$count = 1;
|
|
|
|
while ( User::idFromName( $preferred_username . $count ) !== null ) {
|
|
|
|
while ( MediaWikiServices::getInstance()
|
|
|
|
$count++;
|
|
|
|
->getUserIdentityLookup()
|
|
|
|
|
|
|
|
->getUserIdentityByName( $preferred_username . $count ) ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$count ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $preferred_username . $count;
|
|
|
|
return $preferred_username . $count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected static function punycodeEnc($str){
|
|
|
|
protected static function punycodeEnc( $str ){
|
|
|
|
$punycode = new PunyCode();
|
|
|
|
$punycode = new PunyCode();
|
|
|
|
return $punycode->encode($str);
|
|
|
|
return $punycode->encode( $str );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|