From 6ef4747e9da5d2048ebd180d63cc97349523ec93 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 16 Mar 2016 06:36:04 -0700 Subject: [PATCH] Convert OAuth1 handshake tokens to new modular temporary tokens Summary: Ref T10603. Swap these over and give them nice UI strings. Test Plan: - Refreshed a Twitter OAuth link. - Unlinked and re-linked a Twitter account. - Viewed the new type in {nav Config > Temporary Tokens}. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10603 Differential Revision: https://secure.phabricator.com/D15480 --- src/__phutil_library_map__.php | 2 ++ .../provider/PhabricatorOAuth1AuthProvider.php | 11 +++++++---- ...habricatorOAuth1SecretTemporaryTokenType.php | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 src/applications/auth/provider/PhabricatorOAuth1SecretTemporaryTokenType.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index efdb6a4eb6..aa0202b656 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2672,6 +2672,7 @@ phutil_register_library_map(array( 'PhabricatorNotificationsApplication' => 'applications/notification/application/PhabricatorNotificationsApplication.php', 'PhabricatorNuanceApplication' => 'applications/nuance/application/PhabricatorNuanceApplication.php', 'PhabricatorOAuth1AuthProvider' => 'applications/auth/provider/PhabricatorOAuth1AuthProvider.php', + 'PhabricatorOAuth1SecretTemporaryTokenType' => 'applications/auth/provider/PhabricatorOAuth1SecretTemporaryTokenType.php', 'PhabricatorOAuth2AuthProvider' => 'applications/auth/provider/PhabricatorOAuth2AuthProvider.php', 'PhabricatorOAuthAuthProvider' => 'applications/auth/provider/PhabricatorOAuthAuthProvider.php', 'PhabricatorOAuthClientAuthorization' => 'applications/oauthserver/storage/PhabricatorOAuthClientAuthorization.php', @@ -7122,6 +7123,7 @@ phutil_register_library_map(array( 'PhabricatorNotificationsApplication' => 'PhabricatorApplication', 'PhabricatorNuanceApplication' => 'PhabricatorApplication', 'PhabricatorOAuth1AuthProvider' => 'PhabricatorOAuthAuthProvider', + 'PhabricatorOAuth1SecretTemporaryTokenType' => 'PhabricatorAuthTemporaryTokenType', 'PhabricatorOAuth2AuthProvider' => 'PhabricatorOAuthAuthProvider', 'PhabricatorOAuthAuthProvider' => 'PhabricatorAuthProvider', 'PhabricatorOAuthClientAuthorization' => array( diff --git a/src/applications/auth/provider/PhabricatorOAuth1AuthProvider.php b/src/applications/auth/provider/PhabricatorOAuth1AuthProvider.php index bc9572061f..530bf30583 100644 --- a/src/applications/auth/provider/PhabricatorOAuth1AuthProvider.php +++ b/src/applications/auth/provider/PhabricatorOAuth1AuthProvider.php @@ -9,8 +9,6 @@ abstract class PhabricatorOAuth1AuthProvider const PROPERTY_CONSUMER_SECRET = 'oauth1:consumer:secret'; const PROPERTY_PRIVATE_KEY = 'oauth1:private:key'; - const TEMPORARY_TOKEN_TYPE = 'oauth1:request:secret'; - protected function getIDKey() { return self::PROPERTY_CONSUMER_KEY; } @@ -215,8 +213,9 @@ abstract class PhabricatorOAuth1AuthProvider private function saveHandshakeTokenSecret($client_code, $secret) { + $secret_type = PhabricatorOAuth1SecretTemporaryTokenType::TOKENTYPE; $key = $this->getHandshakeTokenKeyFromClientCode($client_code); - $type = $this->getTemporaryTokenType(self::TEMPORARY_TOKEN_TYPE); + $type = $this->getTemporaryTokenType($secret_type); // Wipe out an existing token, if one exists. $token = id(new PhabricatorAuthTemporaryTokenQuery()) @@ -238,8 +237,9 @@ abstract class PhabricatorOAuth1AuthProvider } private function loadHandshakeTokenSecret($client_code) { + $secret_type = PhabricatorOAuth1SecretTemporaryTokenType::TOKENTYPE; $key = $this->getHandshakeTokenKeyFromClientCode($client_code); - $type = $this->getTemporaryTokenType(self::TEMPORARY_TOKEN_TYPE); + $type = $this->getTemporaryTokenType($secret_type); $token = id(new PhabricatorAuthTemporaryTokenQuery()) ->setViewer(PhabricatorUser::getOmnipotentUser()) @@ -263,6 +263,9 @@ abstract class PhabricatorOAuth1AuthProvider // others' toes if a user starts Mediawiki and Bitbucket auth at the // same time. + // TODO: This isn't really a proper use of the table and should get + // cleaned up some day: the type should be constant. + return $core_type.':'.$this->getProviderConfig()->getID(); } diff --git a/src/applications/auth/provider/PhabricatorOAuth1SecretTemporaryTokenType.php b/src/applications/auth/provider/PhabricatorOAuth1SecretTemporaryTokenType.php new file mode 100644 index 0000000000..b104427bfa --- /dev/null +++ b/src/applications/auth/provider/PhabricatorOAuth1SecretTemporaryTokenType.php @@ -0,0 +1,17 @@ +