@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add Persona auth provider

Summary: Ref T3958. Adds a provider for Mozilla's Persona auth.

Test Plan:
- Created a Persona provider.
- Registered a new account with Persona.
- Logged in with Persona.
- Linked an account with Persona.
- Dissolved an account link with Persona.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3958

Differential Revision: https://secure.phabricator.com/D7313

+143 -5
+14
src/__celerity_resource_map__.php
··· 1949 1949 ), 1950 1950 'disk' => '/rsrc/js/application/owners/owners-path-editor.js', 1951 1951 ), 1952 + 'javelin-behavior-persona-login' => 1953 + array( 1954 + 'uri' => '/res/128fdf56/rsrc/js/application/auth/behavior-persona-login.js', 1955 + 'type' => 'js', 1956 + 'requires' => 1957 + array( 1958 + 0 => 'javelin-behavior', 1959 + 1 => 'javelin-resource', 1960 + 2 => 'javelin-stratcom', 1961 + 3 => 'javelin-workflow', 1962 + 4 => 'javelin-util', 1963 + ), 1964 + 'disk' => '/rsrc/js/application/auth/behavior-persona-login.js', 1965 + ), 1952 1966 'javelin-behavior-phabricator-active-nav' => 1953 1967 array( 1954 1968 'uri' => '/res/9c8d3df8/rsrc/js/core/behavior-active-nav.js',
+2
src/__phutil_library_map__.php
··· 962 962 'PhabricatorAuthProviderOAuthGoogle' => 'applications/auth/provider/PhabricatorAuthProviderOAuthGoogle.php', 963 963 'PhabricatorAuthProviderOAuthTwitch' => 'applications/auth/provider/PhabricatorAuthProviderOAuthTwitch.php', 964 964 'PhabricatorAuthProviderPassword' => 'applications/auth/provider/PhabricatorAuthProviderPassword.php', 965 + 'PhabricatorAuthProviderPersona' => 'applications/auth/provider/PhabricatorAuthProviderPersona.php', 965 966 'PhabricatorAuthRegisterController' => 'applications/auth/controller/PhabricatorAuthRegisterController.php', 966 967 'PhabricatorAuthStartController' => 'applications/auth/controller/PhabricatorAuthStartController.php', 967 968 'PhabricatorAuthUnlinkController' => 'applications/auth/controller/PhabricatorAuthUnlinkController.php', ··· 3116 3117 'PhabricatorAuthProviderOAuthGoogle' => 'PhabricatorAuthProviderOAuth', 3117 3118 'PhabricatorAuthProviderOAuthTwitch' => 'PhabricatorAuthProviderOAuth', 3118 3119 'PhabricatorAuthProviderPassword' => 'PhabricatorAuthProvider', 3120 + 'PhabricatorAuthProviderPersona' => 'PhabricatorAuthProvider', 3119 3121 'PhabricatorAuthRegisterController' => 'PhabricatorAuthController', 3120 3122 'PhabricatorAuthStartController' => 'PhabricatorAuthController', 3121 3123 'PhabricatorAuthUnlinkController' => 'PhabricatorAuthController',
+7 -5
src/applications/auth/provider/PhabricatorAuthProvider.php
··· 384 384 array( 385 385 'method' => 'optional string', 386 386 'uri' => 'string', 387 + 'sigil' => 'optional string', 387 388 )); 388 389 389 390 $viewer = $request->getUser(); ··· 404 405 ->setSpriteIcon($this->getLoginIcon()); 405 406 406 407 $button = id(new PHUIButtonView()) 407 - ->setSize(PHUIButtonView::BIG) 408 - ->setColor(PHUIButtonView::GREY) 409 - ->setIcon($icon) 410 - ->setText($button_text) 411 - ->setSubtext($this->getProviderName()); 408 + ->setSize(PHUIButtonView::BIG) 409 + ->setColor(PHUIButtonView::GREY) 410 + ->setIcon($icon) 411 + ->setText($button_text) 412 + ->setSubtext($this->getProviderName()); 412 413 413 414 $uri = $attributes['uri']; 414 415 $uri = new PhutilURI($uri); ··· 432 433 array( 433 434 'method' => idx($attributes, 'method', 'GET'), 434 435 'action' => (string)$uri, 436 + 'sigil' => idx($attributes, 'sigil'), 435 437 ), 436 438 $content); 437 439 }
+79
src/applications/auth/provider/PhabricatorAuthProviderPersona.php
··· 1 + <?php 2 + 3 + final class PhabricatorAuthProviderPersona 4 + extends PhabricatorAuthProvider { 5 + 6 + private $adapter; 7 + 8 + public function getProviderName() { 9 + return pht('Persona'); 10 + } 11 + 12 + public function getDescriptionForCreate() { 13 + return pht( 14 + 'Allow users to login or register using Mozilla Persona.'); 15 + } 16 + 17 + public function getAdapter() { 18 + if (!$this->adapter) { 19 + $adapter = new PhutilAuthAdapterPersona(); 20 + $this->adapter = $adapter; 21 + } 22 + return $this->adapter; 23 + } 24 + 25 + protected function renderLoginForm( 26 + AphrontRequest $request, 27 + $mode) { 28 + 29 + Javelin::initBehavior( 30 + 'persona-login', 31 + array( 32 + 'loginURI' => $this->getLoginURI(), 33 + )); 34 + 35 + return $this->renderStandardLoginButton( 36 + $request, 37 + $mode, 38 + array( 39 + 'uri' => $this->getLoginURI(), 40 + 'sigil' => 'persona-login-form', 41 + )); 42 + } 43 + 44 + public function isLoginFormAButton() { 45 + return true; 46 + } 47 + 48 + public function processLoginRequest( 49 + PhabricatorAuthLoginController $controller) { 50 + 51 + $request = $controller->getRequest(); 52 + $adapter = $this->getAdapter(); 53 + 54 + $account = null; 55 + $response = null; 56 + 57 + if (!$request->isAjax()) { 58 + throw new Exception("Expected this request to come via Ajax."); 59 + } 60 + 61 + $assertion = $request->getStr('assertion'); 62 + if (!$assertion) { 63 + throw new Exception("Expected identity assertion."); 64 + } 65 + 66 + $adapter->setAssertion($assertion); 67 + $adapter->setAudience(PhabricatorEnv::getURI('/')); 68 + 69 + try { 70 + $account_id = $adapter->getAccountID(); 71 + } catch (Exception $ex) { 72 + // TODO: Handle this in a more user-friendly way. 73 + throw $ex; 74 + } 75 + 76 + return array($this->loadOrCreateAccount($account_id), $response); 77 + } 78 + 79 + }
+41
webroot/rsrc/js/application/auth/behavior-persona-login.js
··· 1 + /** 2 + * @provides javelin-behavior-persona-login 3 + * @requires javelin-behavior 4 + * javelin-resource 5 + * javelin-stratcom 6 + * javelin-workflow 7 + * javelin-util 8 + */ 9 + 10 + JX.behavior('persona-login', function(config) { 11 + 12 + JX.Stratcom.listen( 13 + 'submit', 14 + 'persona-login-form', 15 + function(e) { 16 + e.kill(); 17 + navigator.id.request(); 18 + }); 19 + 20 + var onloaded = function() { 21 + // Before installing watch(), log the user out, because we know they don't 22 + // have a valid session if they're hitting this page. If we don't do this, 23 + // Persona may immediately trigger a login event, which prevents the user 24 + // from selecting another authentication mechanism. 25 + navigator.id.logout(); 26 + 27 + navigator.id.watch({ 28 + loggedInUser: null, 29 + onlogin: onlogin, 30 + onlogout: JX.bag 31 + }); 32 + }; 33 + 34 + var onlogin = function(assertion) { 35 + new JX.Workflow(config.loginURI, {assertion: assertion}) 36 + .start(); 37 + }; 38 + 39 + var persona_library = 'https://login.persona.org/include.js'; 40 + JX.Resource.load(persona_library, onloaded); 41 + });