Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/auth/adapter/PhutilDisqusAuthAdapter.php
12256 views
1
<?php
2
3
/**
4
* Authentication adapter for Disqus OAuth2.
5
*/
6
final class PhutilDisqusAuthAdapter extends PhutilOAuthAuthAdapter {
7
8
public function getAdapterType() {
9
return 'disqus';
10
}
11
12
public function getAdapterDomain() {
13
return 'disqus.com';
14
}
15
16
public function getAccountID() {
17
return $this->getOAuthAccountData('id');
18
}
19
20
public function getAccountEmail() {
21
return $this->getOAuthAccountData('email');
22
}
23
24
public function getAccountName() {
25
return $this->getOAuthAccountData('username');
26
}
27
28
public function getAccountImageURI() {
29
return $this->getOAuthAccountData('avatar', 'permalink');
30
}
31
32
public function getAccountURI() {
33
return $this->getOAuthAccountData('profileUrl');
34
}
35
36
public function getAccountRealName() {
37
return $this->getOAuthAccountData('name');
38
}
39
40
protected function getAuthenticateBaseURI() {
41
return 'https://disqus.com/api/oauth/2.0/authorize/';
42
}
43
44
protected function getTokenBaseURI() {
45
return 'https://disqus.com/api/oauth/2.0/access_token/';
46
}
47
48
public function getScope() {
49
return 'read';
50
}
51
52
public function getExtraAuthenticateParameters() {
53
return array(
54
'response_type' => 'code',
55
);
56
}
57
58
public function getExtraTokenParameters() {
59
return array(
60
'grant_type' => 'authorization_code',
61
);
62
}
63
64
protected function loadOAuthAccountData() {
65
$uri = new PhutilURI('https://disqus.com/api/3.0/users/details.json');
66
$uri->replaceQueryParam('api_key', $this->getClientID());
67
$uri->replaceQueryParam('access_token', $this->getAccessToken());
68
$uri = (string)$uri;
69
70
$future = new HTTPSFuture($uri);
71
$future->setMethod('GET');
72
list($body) = $future->resolvex();
73
74
try {
75
$data = phutil_json_decode($body);
76
return $data['response'];
77
} catch (PhutilJSONParserException $ex) {
78
throw new PhutilProxyException(
79
pht('Expected valid JSON response from Disqus account data request.'),
80
$ex);
81
}
82
}
83
84
}
85
86