Changeset View
Changeset View
Standalone View
Standalone View
src/applications/auth/factor/PhabricatorAuthFactor.php
| Show First 20 Lines • Show All 141 Lines • ▼ Show 20 Lines | final public function getNewIssuedChallenges( | ||||
| // challenges, particularly push factors like SMS. | // challenges, particularly push factors like SMS. | ||||
| $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); | $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); | ||||
| $new_challenges = $this->newIssuedChallenges( | $new_challenges = $this->newIssuedChallenges( | ||||
| $config, | $config, | ||||
| $viewer, | $viewer, | ||||
| $challenges); | $challenges); | ||||
| if ($new_challenges instanceof PhabricatorAuthFactorResult) { | if ($this->isAuthResult($new_challenges)) { | ||||
| unset($unguarded); | unset($unguarded); | ||||
| return $new_challenges; | return $new_challenges; | ||||
| } | } | ||||
| assert_instances_of($new_challenges, 'PhabricatorAuthChallenge'); | assert_instances_of($new_challenges, 'PhabricatorAuthChallenge'); | ||||
| foreach ($new_challenges as $new_challenge) { | foreach ($new_challenges as $new_challenge) { | ||||
| $ttl = $new_challenge->getChallengeTTL(); | $ttl = $new_challenge->getChallengeTTL(); | ||||
| Show All 36 Lines | $result = $this->newResultFromIssuedChallenges( | ||||
| $config, | $config, | ||||
| $viewer, | $viewer, | ||||
| $challenges); | $challenges); | ||||
| if ($result === null) { | if ($result === null) { | ||||
| return $result; | return $result; | ||||
| } | } | ||||
| if (!($result instanceof PhabricatorAuthFactorResult)) { | if (!$this->isAuthResult($result)) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'Expected "newResultFromIssuedChallenges()" to return null or '. | 'Expected "newResultFromIssuedChallenges()" to return null or '. | ||||
| 'an object of class "%s"; got something else (in "%s").', | 'an object of class "%s"; got something else (in "%s").', | ||||
| 'PhabricatorAuthFactorResult', | 'PhabricatorAuthFactorResult', | ||||
| get_class($this))); | get_class($this))); | ||||
| } | } | ||||
| Show All 15 Lines | final public function getResultFromChallengeResponse( | ||||
| assert_instances_of($challenges, 'PhabricatorAuthChallenge'); | assert_instances_of($challenges, 'PhabricatorAuthChallenge'); | ||||
| $result = $this->newResultFromChallengeResponse( | $result = $this->newResultFromChallengeResponse( | ||||
| $config, | $config, | ||||
| $viewer, | $viewer, | ||||
| $request, | $request, | ||||
| $challenges); | $challenges); | ||||
| if (!($result instanceof PhabricatorAuthFactorResult)) { | if (!$this->isAuthResult($result)) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'Expected "newResultFromChallengeResponse()" to return an object '. | 'Expected "newResultFromChallengeResponse()" to return an object '. | ||||
| 'of class "%s"; got something else (in "%s").', | 'of class "%s"; got something else (in "%s").', | ||||
| 'PhabricatorAuthFactorResult', | 'PhabricatorAuthFactorResult', | ||||
| get_class($this))); | get_class($this))); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 159 Lines • ▼ Show 20 Lines | if (!$sync_token) { | ||||
| ->setTokenType($sync_type) | ->setTokenType($sync_type) | ||||
| ->setTokenCode($sync_key_digest) | ->setTokenCode($sync_key_digest) | ||||
| ->setTokenExpires($now + $sync_ttl); | ->setTokenExpires($now + $sync_ttl); | ||||
| $properties = $this->newMFASyncTokenProperties( | $properties = $this->newMFASyncTokenProperties( | ||||
| $provider, | $provider, | ||||
| $user); | $user); | ||||
| if ($this->isAuthResult($properties)) { | |||||
| return $properties; | |||||
| } | |||||
| foreach ($properties as $key => $value) { | foreach ($properties as $key => $value) { | ||||
| $sync_token->setTemporaryTokenProperty($key, $value); | $sync_token->setTemporaryTokenProperty($key, $value); | ||||
| } | } | ||||
| $sync_token->save(); | $sync_token->save(); | ||||
| } | } | ||||
| $form->addHiddenInput($this->getMFASyncTokenFormKey(), $sync_key); | $form->addHiddenInput($this->getMFASyncTokenFormKey(), $sync_key); | ||||
| ▲ Show 20 Lines • Show All 131 Lines • ▼ Show 20 Lines | final protected function loadConfigurationsForProvider( | ||||
| return id(new PhabricatorAuthFactorConfigQuery()) | return id(new PhabricatorAuthFactorConfigQuery()) | ||||
| ->setViewer($user) | ->setViewer($user) | ||||
| ->withUserPHIDs(array($user->getPHID())) | ->withUserPHIDs(array($user->getPHID())) | ||||
| ->withFactorProviderPHIDs(array($provider->getPHID())) | ->withFactorProviderPHIDs(array($provider->getPHID())) | ||||
| ->execute(); | ->execute(); | ||||
| } | } | ||||
| final protected function isAuthResult($object) { | |||||
| return ($object instanceof PhabricatorAuthFactorResult); | |||||
| } | |||||
| } | } | ||||