Skip to content

Commit 60e20e8

Browse files
authored
Update PhutilMediaWikiAuthAdapter.php
1 parent 75bafe6 commit 60e20e8

File tree

1 file changed

+35
-42
lines changed

1 file changed

+35
-42
lines changed

src/oauth/PhutilMediaWikiAuthAdapter.php

Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,26 @@ public function getWikiPageURI($title, $query_params = null) {
3636
'&'));
3737
}
3838

39+
public function getAdapterDomain() {
40+
return $this->domain;
41+
}
42+
43+
public function setAdapterDomain($domain) {
44+
$this->adapterDomain = $domain;
45+
return $this;
46+
}
47+
48+
public function getAdapterType() {
49+
return 'mediawiki';
50+
}
51+
3952
public function getAccountID() {
4053
$this->getHandshakeData();
4154
return idx($this->loadOAuthAccountData(), 'userid');
4255
}
43-
44-
public function getAccountName() {
45-
return idx($this->loadOAuthAccountData(), 'username');
56+
57+
public function getAccountEmail() {
58+
return idx($this->loadOAuthAccountData(), 'confirmed_email');
4659
}
4760

4861
public function getAccountURI() {
@@ -52,23 +65,26 @@ public function getAccountURI() {
5265
}
5366
return null;
5467
}
55-
56-
public function getAccountImageURI() {
57-
$info = $this->loadOAuthAccountData();
58-
return idx($info, 'profile_image_url');
68+
69+
public function getAccountName() {
70+
return idx($this->loadOAuthAccountData(), 'username');
5971
}
6072

6173
public function getAccountRealName() {
6274
$info = $this->loadOAuthAccountData();
63-
return idx($info, 'name');
75+
return idx($info, 'realname');
6476
}
65-
66-
public function getAdapterType() {
67-
return 'mediawiki';
77+
78+
protected function getAuthenticateBaseURI() {
79+
return $this->getMediaWikiURI('rest.php/oauth2/authorize/');
6880
}
69-
70-
public function getAdapterDomain() {
71-
return $this->domain;
81+
82+
protected function getTokenBaseURI() {
83+
return $this->getMediaWikiURI('rest.php/oauth2/access_token/');
84+
}
85+
86+
public function getScope() {
87+
return '';
7288
}
7389

7490
public function getExtraAuthenticateParameters() {
@@ -83,36 +99,9 @@ public function getExtraTokenParameters() {
8399
);
84100
}
85101

86-
/* mediawiki oauth needs the callback uri to be "oob"
87-
(out of band callback) */
88-
public function getCallbackURI() {
89-
return $this->callback_uri;
90-
}
91-
92-
public function setCallbackURI($uri) {
93-
$this->callback_uri = $uri;
94-
}
95-
96-
public function shouldAddCSRFTokenToCallbackURI() {
97-
return false;
98-
}
99-
100-
protected function getAuthenticateBaseURI() {
101-
return $this->getMediaWikiBaseURI('rest.php/oauth2/authorize/');
102-
}
103-
104-
public function setAdapterDomain($domain) {
105-
$this->domain = $domain;
106-
return $this;
107-
}
108-
109-
protected function getTokenBaseURI() {
110-
return $this->getMediaWikiBaseURI('rest.php/oauth2/access_token/');
111-
}
112-
113102
protected function loadOAuthAccountData() {
114103
if ($this->userinfo === null) {
115-
$uri = id(new PhutilURI($this->getMediaWikiBaseURI('rest.php/oauth2/resource/profile')))
104+
$uri = id(new PhutilURI($this->getMediaWikiURI('rest.php/oauth2/resource/profile')))
116105
->replaceQueryParam('access_token', $this->getAccessToken());
117106
list($body) = id(new HTTPSFuture($uri))->resolvex();
118107
try {
@@ -134,4 +123,8 @@ protected function willProcessTokenRequestResponse($body) {
134123
pht('OAuth provider returned an error response.'));
135124
}
136125
}
126+
127+
private function getMediaWikiURI($path) {
128+
return rtrim($this->mediaWikiBaseURI, '/').'/'.ltrim($path, '/');
129+
}
137130
}

0 commit comments

Comments
 (0)