CSteipp has uploaded a new change for review.
https://gerrit.wikimedia.org/r/77485
Change subject: DO NOT MERGE - OAuth Sessions
......................................................................
DO NOT MERGE - OAuth Sessions
Ugly hack to have OAuth keep sessions, just to get things working
Change-Id: Ie03bfc366661618ecf41d2bfb6b9618ba3ffd288
---
M api/MWOAuthAPI.setup.php
1 file changed, 44 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/OAuth
refs/changes/85/77485/1
diff --git a/api/MWOAuthAPI.setup.php b/api/MWOAuthAPI.setup.php
index 23767f7..1c49eb0 100644
--- a/api/MWOAuthAPI.setup.php
+++ b/api/MWOAuthAPI.setup.php
@@ -65,6 +65,47 @@
$hooks['UserGetRights'][] = __CLASS__ . '::onUserGetRights';
$hooks['UserIsEveryoneAllowed'][] = __CLASS__ .
'::onUserIsEveryoneAllowed';
$hooks['ApiCheckCanExecute'][] = __CLASS__ .
'::onApiCheckCanExecute';
+
+ $hooks['GetSessionData'][] = __CLASS__ . '::onGetSessionData';
+ $hooks['SetSessionData'][] = __CLASS__ . '::onSetSessionData';
+ }
+
+ public static function onGetSessionData( $key, &$data ) {
+ wfDebugLog( 'OAuth', __METHOD__ . ": Session id " .
session_id() );
+ $phpSessionId = session_id();
+ if ( !$phpSessionId || strpos( $phpSessionId, 'oauth-' ) !== 0
) {
+ return true;
+ }
+
+ $sessionKey = MWOAuthUtils::getCacheKey( 'session',
$phpSessionId );
+ global $wgUser, $wgMemc;
+ $oauthSession = $wgMemc->get( $sessionKey );
+
+ if ( $oauthSession ) {
+ wfDebugLog( 'OAuth', __METHOD__ . ": getting '$key'
from " . print_r( $oauthSession, true ) );
+ if ( isset( $oauthSession[$key] ) ) {
+ $data = $oauthSession[$key];
+ }
+ }
+ return true;
+ }
+
+ public static function onSetSessionData( $key, $data ) {
+ wfDebugLog( 'OAuth', __METHOD__ . ": Session id " .
session_id() );
+ $phpSessionId = session_id();
+ if ( !$phpSessionId || strpos( $phpSessionId, 'oauth-' ) !== 0
) {
+ return true;
+ }
+ $sessionKey = MWOAuthUtils::getCacheKey( 'session',
$phpSessionId );
+ global $wgUser, $wgMemc;
+ $oauthSession = $wgMemc->get( $sessionKey );
+ if ( !$oauthSession ) {
+ $oauthSession = array();
+ }
+ $oauthSession[$key] = $data;
+ wfDebugLog( 'OAuth', __METHOD__ . ": setting '$key' int " .
print_r( $oauthSession, true ) );
+ $wgMemc->set( $sessionKey, $oauthSession, 3600 );
+ return true;
}
/**
@@ -104,6 +145,8 @@
'accesstoken' => $accesstoken,
'rights' =>
MWOAuthUtils::getGrantRights( $access->get( 'grants' ) ),
);
+ session_start();
+ session_id( 'oauth-' . $accesstoken->key );
$result = true;
}
} catch( ErrorPageError $ex ) {
@@ -115,6 +158,7 @@
$result = false;
return false;
}
+ wfDebugLog( 'OAuth', __METHOD__ . ": Session id " .
session_id() );
return true;
}
--
To view, visit https://gerrit.wikimedia.org/r/77485
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie03bfc366661618ecf41d2bfb6b9618ba3ffd288
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/OAuth
Gerrit-Branch: master
Gerrit-Owner: CSteipp <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits