3 abstract class PhabricatorOAuthAuthProvider
extends PhabricatorAuthProvider
{
5 const PROPERTY_NOTE
= 'oauth:app:note';
9 abstract protected function newOAuthAdapter();
10 abstract protected function getIDKey();
11 abstract protected function getSecretKey();
13 public function getDescriptionForCreate() {
14 return pht('Configure %s OAuth.', $this->getProviderName());
17 public function getAdapter() {
18 if (!$this->adapter
) {
19 $adapter = $this->newOAuthAdapter();
20 $this->adapter
= $adapter;
21 $this->configureAdapter($adapter);
23 return $this->adapter
;
26 public function isLoginFormAButton() {
30 public function readFormValuesFromProvider() {
31 $config = $this->getProviderConfig();
32 $id = $config->getProperty($this->getIDKey());
33 $secret = $config->getProperty($this->getSecretKey());
34 $note = $config->getProperty(self
::PROPERTY_NOTE
);
37 $this->getIDKey() => $id,
38 $this->getSecretKey() => $secret,
39 self
::PROPERTY_NOTE
=> $note,
43 public function readFormValuesFromRequest(AphrontRequest
$request) {
45 $this->getIDKey() => $request->getStr($this->getIDKey()),
46 $this->getSecretKey() => $request->getStr($this->getSecretKey()),
47 self
::PROPERTY_NOTE
=> $request->getStr(self
::PROPERTY_NOTE
),
51 protected function processOAuthEditForm(
52 AphrontRequest
$request,
59 $key_id = $this->getIDKey();
60 $key_secret = $this->getSecretKey();
62 if (!strlen($values[$key_id])) {
63 $errors[] = $id_error;
64 $issues[$key_id] = pht('Required');
67 if (!strlen($values[$key_secret])) {
68 $errors[] = $secret_error;
69 $issues[$key_secret] = pht('Required');
72 // If the user has not changed the secret, don't update it (that is,
73 // don't cause a bunch of "****" to be written to the database).
74 if (preg_match('/^[*]+$/', $values[$key_secret])) {
75 unset($values[$key_secret]);
78 return array($errors, $issues, $values);
81 public function getConfigurationHelp() {
82 $help = $this->getProviderConfigurationHelp();
86 'Use the **OAuth App Notes** field to record details about which '.
87 'account the external application is registered under.');
90 abstract protected function getProviderConfigurationHelp();
92 protected function extendOAuthEditForm(
93 AphrontRequest
$request,
94 AphrontFormView
$form,
100 $key_id = $this->getIDKey();
101 $key_secret = $this->getSecretKey();
102 $key_note = self
::PROPERTY_NOTE
;
104 $v_id = $values[$key_id];
105 $v_secret = $values[$key_secret];
107 $v_secret = str_repeat('*', strlen($v_secret));
109 $v_note = $values[$key_note];
111 $e_id = idx($issues, $key_id, $request->isFormPost() ?
null : true);
112 $e_secret = idx($issues, $key_secret, $request->isFormPost() ?
null : true);
116 id(new AphrontFormTextControl())
117 ->setLabel($id_label)
122 id(new AphrontFormPasswordControl())
123 ->setLabel($secret_label)
124 ->setDisableAutocomplete(true)
125 ->setName($key_secret)
126 ->setValue($v_secret)
127 ->setError($e_secret))
129 id(new AphrontFormTextAreaControl())
130 ->setLabel(pht('OAuth App Notes'))
131 ->setHeight(AphrontFormTextAreaControl
::HEIGHT_VERY_SHORT
)
133 ->setValue($v_note));
136 public function renderConfigPropertyTransactionTitle(
137 PhabricatorAuthProviderConfigTransaction
$xaction) {
139 $author_phid = $xaction->getAuthorPHID();
140 $old = $xaction->getOldValue();
141 $new = $xaction->getNewValue();
142 $key = $xaction->getMetadataValue(
143 PhabricatorAuthProviderConfigTransaction
::PROPERTY_KEY
);
146 case self
::PROPERTY_NOTE
:
149 '%s updated the OAuth application notes for this provider.',
150 $xaction->renderHandleLink($author_phid));
153 '%s set the OAuth application notes for this provider.',
154 $xaction->renderHandleLink($author_phid));
159 return parent
::renderConfigPropertyTransactionTitle($xaction);
162 protected function willSaveAccount(PhabricatorExternalAccount
$account) {
163 parent
::willSaveAccount($account);
164 $this->synchronizeOAuthAccount($account);
167 abstract protected function synchronizeOAuthAccount(
168 PhabricatorExternalAccount
$account);