Florianschmidtwelzow has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/289099

Change subject: WIP: Rewrite GoogleLogin to be a PrimaryAuthenticationProvider
......................................................................

WIP: Rewrite GoogleLogin to be a PrimaryAuthenticationProvider

... it's still a long long long way...

Bug: T110294
Change-Id: I0d0447eb35ff38fab8bd4d945469cd66cabe0f73
---
M extension.json
M includes/GoogleLogin.body.php
A includes/auth/GooglePrimaryAuthenticationProvider.php
3 files changed, 73 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GoogleLogin 
refs/changes/99/289099/1

diff --git a/extension.json b/extension.json
index 16d9156..628abe3 100644
--- a/extension.json
+++ b/extension.json
@@ -41,6 +41,7 @@
                "SpecialManageGoogleLogin": 
"includes/specials/SpecialManageGoogleLogin.php",
                "GoogleLoginHooks": "includes/GoogleLogin.hooks.php",
                "GoogleLogin\\GoogleUser": "includes/GoogleUser.php",
+               "GoogleLogin\\Auth\\GooglePrimaryAuthenticationProvider": 
"includes/auth/GooglePrimaryAuthenticationProvider.php",
                "ApiGoogleLoginInfo": "includes/api/ApiGoogleLoginInfo.php"
        },
        "ResourceModules": {
diff --git a/includes/GoogleLogin.body.php b/includes/GoogleLogin.body.php
index 85d6696..d4d14ff 100755
--- a/includes/GoogleLogin.body.php
+++ b/includes/GoogleLogin.body.php
@@ -98,7 +98,7 @@
         * @return string GL special page local url
         */
        public function getSpecialPageUri() {
-               return $this->getSpecialPageTitle()->getLocalUrl();
+               return SpecialPage::getTitleFor( 'UserLogin' )->getLocalUrl();
        }
 
        /**
diff --git a/includes/auth/GooglePrimaryAuthenticationProvider.php 
b/includes/auth/GooglePrimaryAuthenticationProvider.php
new file mode 100644
index 0000000..22378ae
--- /dev/null
+++ b/includes/auth/GooglePrimaryAuthenticationProvider.php
@@ -0,0 +1,71 @@
+<?php
+
+namespace GoogleLogin\Auth;
+
+use MediaWiki\Auth\AuthenticationRequest;
+use MediaWiki\Auth\AbstractPrimaryAuthenticationProvider;
+use MediaWiki\Auth\AuthManager;
+use MediaWiki\Auth\ButtonAuthenticationRequest;
+use MediaWiki\Auth\AuthenticationResponse;
+
+use GoogleLogin\GoogleUser;
+use GoogleLogin;
+
+use StatusValue;
+
+/**
+ * Created by PhpStorm.
+ * User: Florian
+ * Date: 16.05.2016
+ * Time: 23:50
+ */
+class GooglePrimaryAuthenticationProvider extends 
AbstractPrimaryAuthenticationProvider {
+       public function beginPrimaryAuthentication( array $reqs ) {
+               $req = ButtonAuthenticationRequest::getRequestByName( $reqs, 
'googlelogin' );
+               if ( !$req ) {
+                       return AuthenticationResponse::newAbstain();
+               }
+               $googleLogin = new GoogleLogin;
+               $client = $googleLogin->getClient();
+               $plus = $googleLogin->getPlus();
+
+               return AuthenticationResponse::newRedirect( [ $req ], 
$client->createAuthUrl() );
+       }
+
+       public function continuePrimaryAuthentication( array $reqs ) {
+               return AuthenticationResponse::FAIL;
+       }
+
+       public function getAuthenticationRequests( $action, array $options ) {
+               switch ( $action ) {
+                       case AuthManager::ACTION_LOGIN:
+                               return [ new ButtonAuthenticationRequest( 
'googlelogin', wfMessage( 'googlelogin' ), new \RawMessage( 'no help yet' ) ) ];
+                               break;
+                       default:
+                               return [];
+               }
+       }
+
+       public function testUserExists( $username, $flags = User::READ_NORMAL ) 
{
+               return GoogleUser::newFromName( $username )->exists();
+       }
+
+       public function providerAllowsAuthenticationDataChange(
+               AuthenticationRequest $req, $checkData = true
+       ) {
+               // TODO: Is this for changing the google id, too?
+               return StatusValue::newGood( 'ignored' );
+       }
+
+       public function providerChangeAuthenticationData( AuthenticationRequest 
$req ) {
+               // TODO: Remove google id from user here?
+       }
+
+       public function accountCreationType() {
+               return self::TYPE_CREATE;
+       }
+
+       public function beginPrimaryAccountCreation( $user, $creator, array 
$reqs ) {
+               return AuthenticationResponse::newAbstain();
+       }
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/289099
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0d0447eb35ff38fab8bd4d945469cd66cabe0f73
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/GoogleLogin
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to