mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/OATHAuth
synced 2024-11-28 02:00:06 +00:00
Fixup DB/uid handling for SUL wikis
We need to pass the db name to getConnection, in addition to wfGetLB. Also, use core's CentralIdLookup for mapping local user to CentralId when using a central DB for OATH secret storage. Change-Id: I12a457633956a9a34dc5302ddcff468e31dd9cef
This commit is contained in:
parent
079877734c
commit
65543e1f6c
|
@ -79,14 +79,15 @@ class OATHAuthHooks {
|
|||
|
||||
$oathrepo = self::getOATHUserRepository();
|
||||
$oathuser = $oathrepo->findByUser( $user );
|
||||
$uid = CentralIdLookup::factory()->centralIdFromLocalUser( $user );
|
||||
|
||||
if ( $oathuser->getKey() !== null && !$request->getCheck( 'token' ) ) {
|
||||
$encData = OATHAuthUtils::encryptSessionData(
|
||||
$request->getValues(),
|
||||
$user->getId()
|
||||
$uid
|
||||
);
|
||||
$request->setSessionData( 'oath_login', $encData );
|
||||
$request->setSessionData( 'oath_uid', $user->getId() );
|
||||
$request->setSessionData( 'oath_uid', $uid );
|
||||
$output->redirect( SpecialPage::getTitleFor( 'OATH' )->getFullURL( '', false, PROTO_CURRENT ) );
|
||||
return false;
|
||||
} else {
|
||||
|
|
|
@ -89,7 +89,8 @@ class OATHAuthKey {
|
|||
|
||||
// Prevent replay attacks
|
||||
$memc = ObjectCache::newAnything( array() );
|
||||
$memcKey = wfMemcKey( 'oauthauth', 'usedtokens', $user->getUser()->getId() );
|
||||
$uid = CentralIdLookup::factory()->centralIdFromLocalUser( $user->getUser() );
|
||||
$memcKey = wfMemcKey( 'oauthauth', 'usedtokens', $uid );
|
||||
$lastWindow = (int)$memc->get( $memcKey );
|
||||
|
||||
$retval = false;
|
||||
|
|
|
@ -6,14 +6,16 @@ class OATHUserRepository {
|
|||
private $dbw;
|
||||
|
||||
public function __construct( LoadBalancer $lb ) {
|
||||
$this->dbr = $lb->getConnection( DB_SLAVE );
|
||||
$this->dbw = $lb->getConnection( DB_MASTER );
|
||||
global $wgOATHAuthDatabase;
|
||||
$this->dbr = $lb->getConnection( DB_SLAVE, array(), $wgOATHAuthDatabase );
|
||||
$this->dbw = $lb->getConnection( DB_MASTER, array(), $wgOATHAuthDatabase );
|
||||
}
|
||||
|
||||
public function findByUser( User $user ) {
|
||||
$oathUser = new OATHUser( $user, null );
|
||||
|
||||
$res = $this->dbr->selectRow( 'oathauth_users', '*', array( 'id' => $user->getId() ), __METHOD__ );
|
||||
$uid = CentralIdLookup::factory()->centralIdFromLocalUser( $user );
|
||||
$res = $this->dbr->selectRow( 'oathauth_users', '*', array( 'id' => $uid ), __METHOD__ );
|
||||
if ($res) {
|
||||
$key = new OATHAuthKey( $res->secret, explode( ',', $res->scratch_tokens ) );
|
||||
$oathUser->setKey( $key );
|
||||
|
@ -27,7 +29,7 @@ class OATHUserRepository {
|
|||
'oathauth_users',
|
||||
array( 'id' ),
|
||||
array(
|
||||
'id' => $user->getUser()->getId(),
|
||||
'id' => CentralIdLookup::factory()->centralIdFromLocalUser( $user->getUser() ),
|
||||
'secret' => $user->getKey()->getSecret(),
|
||||
'scratch_tokens' => implode( ',', $user->getKey()->getScratchTokens() ),
|
||||
),
|
||||
|
@ -38,7 +40,7 @@ class OATHUserRepository {
|
|||
public function remove( OATHUser $user ) {
|
||||
$this->dbw->delete(
|
||||
'oathauth_users',
|
||||
array( 'id' => $user->getUser()->getId() ),
|
||||
array( 'id' => CentralIdLookup::factory()->centralIdFromLocalUser( $user->getUser() ) ),
|
||||
__METHOD__
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue