diff --git a/src/applications/auth/adapter/PhutilFacebookAuthAdapter.php b/src/applications/auth/adapter/PhutilFacebookAuthAdapter.php index ab569a14a0..9d087bbd37 100644 --- a/src/applications/auth/adapter/PhutilFacebookAuthAdapter.php +++ b/src/applications/auth/adapter/PhutilFacebookAuthAdapter.php @@ -1,114 +1,91 @@ requireSecureBrowsing = $require_secure_browsing; - return $this; - } - public function getAdapterType() { return 'facebook'; } public function getAdapterDomain() { return 'facebook.com'; } public function getAccountID() { return $this->getOAuthAccountData('id'); } public function getAccountEmail() { return $this->getOAuthAccountData('email'); } public function getAccountName() { $link = $this->getOAuthAccountData('link'); if (!$link) { return null; } $matches = null; if (!preg_match('@/([^/]+)$@', $link, $matches)) { return null; } return $matches[1]; } public function getAccountImageURI() { $picture = $this->getOAuthAccountData('picture'); if ($picture) { $picture_data = idx($picture, 'data'); if ($picture_data) { return idx($picture_data, 'url'); } } return null; } public function getAccountURI() { return $this->getOAuthAccountData('link'); } public function getAccountRealName() { return $this->getOAuthAccountData('name'); } - public function getAccountSecuritySettings() { - return $this->getOAuthAccountData('security_settings'); - } - protected function getAuthenticateBaseURI() { return 'https://www.facebook.com/dialog/oauth'; } protected function getTokenBaseURI() { return 'https://graph.facebook.com/oauth/access_token'; } protected function loadOAuthAccountData() { $fields = array( 'id', 'name', 'email', 'link', - 'security_settings', 'picture', ); $uri = new PhutilURI('https://graph.facebook.com/me'); $uri->replaceQueryParam('access_token', $this->getAccessToken()); $uri->replaceQueryParam('fields', implode(',', $fields)); list($body) = id(new HTTPSFuture($uri))->resolvex(); $data = null; try { $data = phutil_json_decode($body); } catch (PhutilJSONParserException $ex) { throw new PhutilProxyException( pht('Expected valid JSON response from Facebook account data request.'), $ex); } - if ($this->requireSecureBrowsing) { - if (empty($data['security_settings']['secure_browsing']['enabled'])) { - throw new Exception( - pht( - 'This Phabricator install requires you to enable Secure Browsing '. - 'on your Facebook account in order to use it to log in to '. - 'Phabricator. For more information, see %s', - 'https://www.facebook.com/help/156201551113407/')); - } - } - return $data; } } diff --git a/src/applications/auth/provider/PhabricatorFacebookAuthProvider.php b/src/applications/auth/provider/PhabricatorFacebookAuthProvider.php index 67840727e8..d7c57b5ddc 100644 --- a/src/applications/auth/provider/PhabricatorFacebookAuthProvider.php +++ b/src/applications/auth/provider/PhabricatorFacebookAuthProvider.php @@ -1,125 +1,65 @@ getLoginURI()); + + $domain = id(new PhutilURI($uri))->getDomain(); + + $table = array( + 'Client OAuth Login' => pht('No'), + 'Web OAuth Login' => pht('Yes'), + 'Enforce HTTPS' => pht('Yes'), + 'Force Web OAuth Reauthentication' => pht('Yes (Optional)'), + 'Embedded Browser OAuth Login' => pht('No'), + 'Use Strict Mode for Redirect URIs' => pht('Yes'), + 'Login from Devices' => pht('No'), + 'Valid OAuth Redirect URIs' => '`'.(string)$uri.'`', + 'App Domains' => '`'.$domain.'`', + ); + + $rows = array(); + foreach ($table as $k => $v) { + $rows[] = sprintf('| %s | %s |', $k, $v); + $rows[] = sprintf('|----| |'); + } + $rows = implode("\n", $rows); + + return pht( 'To configure Facebook OAuth, create a new Facebook Application here:'. "\n\n". 'https://developers.facebook.com/apps'. "\n\n". 'You should use these settings in your application:'. "\n\n". - " - **Site URL**: Set this to `%s`\n". - " - **Valid OAuth redirect URIs**: You should also set this to `%s`\n". - " - **Client OAuth Login**: Set this to **OFF**.\n". - " - **Embedded browser OAuth Login**: Set this to **OFF**.\n". + "%s\n". "\n\n". - "Some of these settings may be in the **Advanced** tab.\n\n". "After creating your new application, copy the **App ID** and ". "**App Secret** to the fields above.", - (string)$uri, - (string)$uri); - } - - public function getDefaultProviderConfig() { - return parent::getDefaultProviderConfig() - ->setProperty(self::KEY_REQUIRE_SECURE, 1); + $rows); } protected function newOAuthAdapter() { - $require_secure = $this->getProviderConfig()->getProperty( - self::KEY_REQUIRE_SECURE); - - return id(new PhutilFacebookAuthAdapter()) - ->setRequireSecureBrowsing($require_secure); + return new PhutilFacebookAuthAdapter(); } protected function getLoginIcon() { return 'Facebook'; } protected function getContentSecurityPolicyFormActions() { return array( // See T13254. After login with a mobile device, Facebook may redirect // to the mobile site. 'https://m.facebook.com/', ); } - public function readFormValuesFromProvider() { - $require_secure = $this->getProviderConfig()->getProperty( - self::KEY_REQUIRE_SECURE); - - return parent::readFormValuesFromProvider() + array( - self::KEY_REQUIRE_SECURE => $require_secure, - ); - } - - public function readFormValuesFromRequest(AphrontRequest $request) { - return parent::readFormValuesFromRequest($request) + array( - self::KEY_REQUIRE_SECURE => $request->getBool(self::KEY_REQUIRE_SECURE), - ); - } - - public function extendEditForm( - AphrontRequest $request, - AphrontFormView $form, - array $values, - array $issues) { - - parent::extendEditForm($request, $form, $values, $issues); - - $key_require = self::KEY_REQUIRE_SECURE; - $v_require = idx($values, $key_require); - - $form - ->appendChild( - id(new AphrontFormCheckboxControl()) - ->addCheckbox( - $key_require, - $v_require, - pht( - "%s ". - "Require users to enable 'secure browsing' on Facebook in order ". - "to use Facebook to authenticate with Phabricator. This ". - "improves security by preventing an attacker from capturing ". - "an insecure Facebook session and escalating it into a ". - "Phabricator session. Enabling it is recommended.", - phutil_tag('strong', array(), pht('Require Secure Browsing:'))))); - } - - public function renderConfigPropertyTransactionTitle( - PhabricatorAuthProviderConfigTransaction $xaction) { - - $author_phid = $xaction->getAuthorPHID(); - $old = $xaction->getOldValue(); - $new = $xaction->getNewValue(); - $key = $xaction->getMetadataValue( - PhabricatorAuthProviderConfigTransaction::PROPERTY_KEY); - - switch ($key) { - case self::KEY_REQUIRE_SECURE: - if ($new) { - return pht( - '%s turned "Require Secure Browsing" on.', - $xaction->renderHandleLink($author_phid)); - } else { - return pht( - '%s turned "Require Secure Browsing" off.', - $xaction->renderHandleLink($author_phid)); - } - } - - return parent::renderConfigPropertyTransactionTitle($xaction); - } - }