2013-06-16 19:15:16 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorAuthProviderOAuthFacebook
|
|
|
|
extends PhabricatorAuthProviderOAuth {
|
|
|
|
|
2013-06-19 00:52:01 +02:00
|
|
|
const KEY_REQUIRE_SECURE = 'oauth:facebook:require-secure';
|
|
|
|
|
2013-06-16 19:15:16 +02:00
|
|
|
public function getProviderName() {
|
|
|
|
return pht('Facebook');
|
|
|
|
}
|
|
|
|
|
2013-06-20 20:17:53 +02:00
|
|
|
public function getDefaultProviderConfig() {
|
|
|
|
return parent::getDefaultProviderConfig()
|
|
|
|
->setProperty(self::KEY_REQUIRE_SECURE, 1);
|
|
|
|
}
|
|
|
|
|
2013-06-16 19:15:16 +02:00
|
|
|
protected function newOAuthAdapter() {
|
2013-06-19 00:52:01 +02:00
|
|
|
$secure_only = PhabricatorEnv::getEnvConfig('facebook.require-https-auth');
|
|
|
|
return id(new PhutilAuthAdapterOAuthFacebook())
|
|
|
|
->setRequireSecureBrowsing($secure_only);
|
2013-06-16 19:15:16 +02:00
|
|
|
}
|
|
|
|
|
2013-06-17 01:31:57 +02:00
|
|
|
protected function getLoginIcon() {
|
|
|
|
return 'Facebook';
|
|
|
|
}
|
|
|
|
|
2013-06-16 19:15:16 +02:00
|
|
|
public function isEnabled() {
|
2013-06-20 20:17:53 +02:00
|
|
|
if ($this->hasProviderConfig()) {
|
|
|
|
return parent::isEnabled();
|
|
|
|
}
|
|
|
|
|
2013-06-16 19:17:29 +02:00
|
|
|
return parent::isEnabled() &&
|
2013-06-16 19:15:16 +02:00
|
|
|
PhabricatorEnv::getEnvConfig('facebook.auth-enabled');
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getOAuthClientID() {
|
|
|
|
return PhabricatorEnv::getEnvConfig('facebook.application-id');
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getOAuthClientSecret() {
|
|
|
|
$secret = PhabricatorEnv::getEnvConfig('facebook.application-secret');
|
|
|
|
if ($secret) {
|
|
|
|
return new PhutilOpaqueEnvelope($secret);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function shouldAllowRegistration() {
|
2013-06-20 20:17:53 +02:00
|
|
|
if ($this->hasProviderConfig()) {
|
|
|
|
return parent::shouldAllowRegistration();
|
|
|
|
}
|
2013-06-16 19:15:16 +02:00
|
|
|
return PhabricatorEnv::getEnvConfig('facebook.registration-enabled');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function shouldAllowAccountUnlink() {
|
2013-06-20 20:17:53 +02:00
|
|
|
if ($this->hasProviderConfig()) {
|
|
|
|
return parent::shouldAllowAccountUnlink();
|
|
|
|
}
|
2013-06-16 19:15:16 +02:00
|
|
|
return !PhabricatorEnv::getEnvConfig('facebook.auth-permanent');
|
|
|
|
}
|
|
|
|
|
2013-06-19 00:52:01 +02:00
|
|
|
public function readFormValuesFromProvider() {
|
|
|
|
$require_secure = PhabricatorEnv::getEnvConfig(
|
|
|
|
'facebook.require-https-auth');
|
|
|
|
|
|
|
|
// TODO: When we read from config, default this on for new providers.
|
|
|
|
|
|
|
|
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.",
|
|
|
|
hsprintf(
|
|
|
|
'<strong>%s</strong>',
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-16 19:15:16 +02:00
|
|
|
}
|