-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(oauth): when requested, include ConsumerAcceptance in oauth data #446
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,7 +107,7 @@ public static function createOauthConsumer($consumerName, $version, $grants, $ca | |
return true; | ||
} | ||
|
||
public static function getOAuthConsumer($consumerName, $version) { | ||
public static function getOAuthConsumer($consumerName, $version, $includeAccess = false) { | ||
$user = self::getUser(); | ||
// TODO create the oauth consumer on the fly if it doesn't exist (needs grants and callbackurl) | ||
|
||
|
@@ -131,10 +131,30 @@ public static function getOAuthConsumer($consumerName, $version) { | |
return false; | ||
} | ||
|
||
return [ | ||
$data = [ | ||
'agent' => $c->getName(), | ||
'consumerKey' => $c->getConsumerKey(), | ||
'consumerSecret' => \MediaWiki\Extension\OAuth\Backend\Utils::hmacDBSecret( $c->getSecretKey() ), | ||
]; | ||
|
||
if ( $includeAccess ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My hacky way of testing this locally would be to short circuit this if statement and always execute the branch, then see if Magnustools Oauth consumers stil work and also receive the additional data. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And you'd be happiest if Magnustools does not get this additional data? My understanding is that we wouldn't want Magnus tools to get these credentials since they would allow editing as the platform reserved user There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Hence the additional parameter, yes |
||
$a = \MediaWiki\Extension\OAuth\Backend\ConsumerAcceptance::newFromUserConsumerWiki( | ||
$db, | ||
$user->getId(), | ||
$c, | ||
$c->getWiki(), | ||
\MediaWiki\Extension\OAuth\Backend\ConsumerAcceptance::READ_NORMAL, | ||
$c->getOAuthVersion(), | ||
); | ||
|
||
if ( $a === false ) { | ||
return false; | ||
} | ||
|
||
$data['accessKey'] = $a->getAccessToken(); | ||
$data['accessSecret'] = $a->getAccessSecret(); | ||
} | ||
|
||
return $data; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking that it could maybe sense to refactor the name of this method to try and make it clear to future callers what the purpose is:
usecase 1 with
$includeAccess = false
is: I want an OAuth consumer that each individual user can authorise to edit on their behalf with their accountusecase 2 with
$includeAccess = true
is: I want credentials to edit the wiki as the PlatformReservedUserI almost wonder if this would be better as a totally separate function. Really the common logic is more "incidental" than "conceptual"; it just happens to be that to get the credentials for usecase 2 you have to get a consumer but really you aren't asking for a consumer but instead editing credentials.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the way
mw
cli works is it expects all 4 tokens, not only theConsumerAcceptance
ones.What we could do though is: always create the consumer with acceptance tokens, and then have a dedicated function that turns the consumer into a response based on the parameter given.