[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/auth/provider/ -> PhabricatorPersonaAuthProvider.php (source)

   1  <?php
   2  
   3  final class PhabricatorPersonaAuthProvider extends PhabricatorAuthProvider {
   4  
   5    private $adapter;
   6  
   7    public function getProviderName() {
   8      return pht('Persona');
   9    }
  10  
  11    public function getDescriptionForCreate() {
  12      return pht(
  13        'Allow users to login or register using Mozilla Persona.');
  14    }
  15  
  16    public function getAdapter() {
  17      if (!$this->adapter) {
  18        $adapter = new PhutilPersonaAuthAdapter();
  19        $this->adapter = $adapter;
  20      }
  21      return $this->adapter;
  22    }
  23  
  24    protected function renderLoginForm(
  25      AphrontRequest $request,
  26      $mode) {
  27  
  28      Javelin::initBehavior(
  29        'persona-login',
  30        array(
  31          'loginURI' => PhabricatorEnv::getURI($this->getLoginURI()),
  32        ));
  33  
  34      return $this->renderStandardLoginButton(
  35        $request,
  36        $mode,
  37        array(
  38          'uri' => $this->getLoginURI(),
  39          'sigil' => 'persona-login-form',
  40        ));
  41    }
  42  
  43    public function isLoginFormAButton() {
  44      return true;
  45    }
  46  
  47    public function processLoginRequest(
  48      PhabricatorAuthLoginController $controller) {
  49  
  50      $request = $controller->getRequest();
  51      $adapter = $this->getAdapter();
  52  
  53      $account = null;
  54      $response = null;
  55  
  56      if (!$request->isAjax()) {
  57        throw new Exception('Expected this request to come via Ajax.');
  58      }
  59  
  60      $assertion = $request->getStr('assertion');
  61      if (!$assertion) {
  62        throw new Exception('Expected identity assertion.');
  63      }
  64  
  65      $adapter->setAssertion($assertion);
  66      $adapter->setAudience(PhabricatorEnv::getURI('/'));
  67  
  68      try {
  69        $account_id = $adapter->getAccountID();
  70      } catch (Exception $ex) {
  71        // TODO: Handle this in a more user-friendly way.
  72        throw $ex;
  73      }
  74  
  75      return array($this->loadOrCreateAccount($account_id), $response);
  76    }
  77  
  78    protected function getLoginIcon() {
  79      return 'Persona';
  80    }
  81  
  82  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1