Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15439499
D9203.id21849.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D9203.id21849.diff
View Options
diff --git a/src/applications/auth/provider/PhabricatorAuthProviderOAuth1MediaWiki.php b/src/applications/auth/provider/PhabricatorAuthProviderOAuth1MediaWiki.php
new file mode 100644
--- /dev/null
+++ b/src/applications/auth/provider/PhabricatorAuthProviderOAuth1MediaWiki.php
@@ -0,0 +1,103 @@
+<?php
+
+final class PhabricatorAuthProviderOAuth1MediaWiki
+ extends PhabricatorAuthProviderOAuth1 {
+
+ public function getProviderName() {
+ return pht('MediaWiki');
+ }
+
+ protected function getProviderConfigurationHelp() {
+ $login_uri = PhabricatorEnv::getURI($this->getLoginURI());
+
+ return pht(
+ "To configure MediaWiki OAuth, create a new application here:".
+ "\n\n".
+ "https://www.mediawiki.org/wiki/Special:OAuthConsumerRegistration/propose".
+ "\n\n".
+ "When creating your application, use these settings:".
+ "\n\n".
+ " - **Callback URL:** Set this to: `%s`".
+ "\n\n".
+ "After completing configuration, copy the **Consumer Key** and ".
+ "**Consumer Secret** to the fields above.",
+ $login_uri);
+ }
+
+ protected function newOAuthAdapter() {
+ return new PhutilAuthAdapterOAuthMediaWiki();
+ }
+
+ protected function getLoginIcon() {
+ return 'MediaWiki';
+ }
+
+ public function processLoginRequest(
+ PhabricatorAuthLoginController $controller) {
+
+ $request = $controller->getRequest();
+ $adapter = $this->getAdapter();
+ $account = null;
+ $response = null;
+
+ if ($request->isHTTPPost()) {
+ $callback_uri = $adapter->getCallbackURI();
+ $adapter->setCallbackURI($callback_uri);
+ $uri = $adapter->getClientRedirectURI();
+ $response = id(new AphrontRedirectResponse())->setURI($uri);
+ return array($account, $response);
+ }
+
+ $denied = $request->getStr('denied');
+ if (strlen($denied)) {
+ // Twitter indicates that the user cancelled the login attempt by
+ // returning "denied" as a parameter.
+ throw new PhutilAuthUserAbortedException();
+ }
+
+ // NOTE: You can get here via GET, this should probably be a bit more
+ // user friendly.
+
+ $token = $request->getStr('oauth_token');
+ $verifier = $request->getStr('oauth_verifier');
+
+ if (!$token) {
+ throw new Exception("Expected 'oauth_token' in request!");
+ }
+
+ if (!$verifier) {
+ throw new Exception("Expected 'oauth_verifier' in request!");
+ }
+
+ list ( $ctok, $csec ) = explode(':', $_COOKIE['mwoauth'], 2);
+ if ($ctok !== $token) {
+ throw new Exception("Token from callback doesn't match your cookie.");
+ }
+
+ $adapter->setToken($token);
+ $adapter->setTokenSecret($csec);
+ $adapter->setVerifier($verifier);
+
+ // NOTE: As a side effect, this will cause the OAuth adapter to request
+ // an access token.
+
+ try {
+ $account_id = $adapter->getAccountID();
+ } catch (Exception $ex) {
+ throw $ex;
+ }
+
+ if (!strlen($account_id)) {
+ $response = $controller->buildProviderErrorResponse(
+ $this,
+ pht(
+ 'The OAuth provider failed to retrieve an account ID.'));
+
+ return array($account, $response);
+ }
+
+ return array($this->loadOrCreateAccount($account_id), $response);
+ }
+
+
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Mar 27, 7:50 AM (3 w, 8 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7718862
Default Alt Text
D9203.id21849.diff (3 KB)
Attached To
Mode
D9203: Configurable MediaWiki oauth1 provider
Attached
Detach File
Event Timeline
Log In to Comment