Changeset View
Changeset View
Standalone View
Standalone View
src/applications/auth/provider/PhabricatorOAuth1AuthProvider.php
Show First 20 Lines • Show All 215 Lines • ▼ Show 20 Lines | /* -( Temporary Secrets )-------------------------------------------------- */ | ||||
private function saveHandshakeTokenSecret($client_code, $secret) { | private function saveHandshakeTokenSecret($client_code, $secret) { | ||||
$key = $this->getHandshakeTokenKeyFromClientCode($client_code); | $key = $this->getHandshakeTokenKeyFromClientCode($client_code); | ||||
$type = $this->getTemporaryTokenType(self::TEMPORARY_TOKEN_TYPE); | $type = $this->getTemporaryTokenType(self::TEMPORARY_TOKEN_TYPE); | ||||
// Wipe out an existing token, if one exists. | // Wipe out an existing token, if one exists. | ||||
$token = id(new PhabricatorAuthTemporaryTokenQuery()) | $token = id(new PhabricatorAuthTemporaryTokenQuery()) | ||||
->setViewer(PhabricatorUser::getOmnipotentUser()) | ->setViewer(PhabricatorUser::getOmnipotentUser()) | ||||
->withObjectPHIDs(array($key)) | ->withTokenResources(array($key)) | ||||
->withTokenTypes(array($type)) | ->withTokenTypes(array($type)) | ||||
->executeOne(); | ->executeOne(); | ||||
if ($token) { | if ($token) { | ||||
$token->delete(); | $token->delete(); | ||||
} | } | ||||
// Save the new secret. | // Save the new secret. | ||||
id(new PhabricatorAuthTemporaryToken()) | id(new PhabricatorAuthTemporaryToken()) | ||||
->setObjectPHID($key) | ->setTokenResource($key) | ||||
->setTokenType($type) | ->setTokenType($type) | ||||
->setTokenExpires(time() + phutil_units('1 hour in seconds')) | ->setTokenExpires(time() + phutil_units('1 hour in seconds')) | ||||
->setTokenCode($secret) | ->setTokenCode($secret) | ||||
->save(); | ->save(); | ||||
} | } | ||||
private function loadHandshakeTokenSecret($client_code) { | private function loadHandshakeTokenSecret($client_code) { | ||||
$key = $this->getHandshakeTokenKeyFromClientCode($client_code); | $key = $this->getHandshakeTokenKeyFromClientCode($client_code); | ||||
$type = $this->getTemporaryTokenType(self::TEMPORARY_TOKEN_TYPE); | $type = $this->getTemporaryTokenType(self::TEMPORARY_TOKEN_TYPE); | ||||
$token = id(new PhabricatorAuthTemporaryTokenQuery()) | $token = id(new PhabricatorAuthTemporaryTokenQuery()) | ||||
->setViewer(PhabricatorUser::getOmnipotentUser()) | ->setViewer(PhabricatorUser::getOmnipotentUser()) | ||||
->withObjectPHIDs(array($key)) | ->withTokenResources(array($key)) | ||||
->withTokenTypes(array($type)) | ->withTokenTypes(array($type)) | ||||
->withExpired(false) | ->withExpired(false) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$token) { | if (!$token) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Unable to load your OAuth1 token secret from storage. It may '. | 'Unable to load your OAuth1 token secret from storage. It may '. | ||||
Show All 23 Lines |