Path: blob/master/src/applications/auth/adapter/PhutilDisqusAuthAdapter.php
12256 views
<?php12/**3* Authentication adapter for Disqus OAuth2.4*/5final class PhutilDisqusAuthAdapter extends PhutilOAuthAuthAdapter {67public function getAdapterType() {8return 'disqus';9}1011public function getAdapterDomain() {12return 'disqus.com';13}1415public function getAccountID() {16return $this->getOAuthAccountData('id');17}1819public function getAccountEmail() {20return $this->getOAuthAccountData('email');21}2223public function getAccountName() {24return $this->getOAuthAccountData('username');25}2627public function getAccountImageURI() {28return $this->getOAuthAccountData('avatar', 'permalink');29}3031public function getAccountURI() {32return $this->getOAuthAccountData('profileUrl');33}3435public function getAccountRealName() {36return $this->getOAuthAccountData('name');37}3839protected function getAuthenticateBaseURI() {40return 'https://disqus.com/api/oauth/2.0/authorize/';41}4243protected function getTokenBaseURI() {44return 'https://disqus.com/api/oauth/2.0/access_token/';45}4647public function getScope() {48return 'read';49}5051public function getExtraAuthenticateParameters() {52return array(53'response_type' => 'code',54);55}5657public function getExtraTokenParameters() {58return array(59'grant_type' => 'authorization_code',60);61}6263protected function loadOAuthAccountData() {64$uri = new PhutilURI('https://disqus.com/api/3.0/users/details.json');65$uri->replaceQueryParam('api_key', $this->getClientID());66$uri->replaceQueryParam('access_token', $this->getAccessToken());67$uri = (string)$uri;6869$future = new HTTPSFuture($uri);70$future->setMethod('GET');71list($body) = $future->resolvex();7273try {74$data = phutil_json_decode($body);75return $data['response'];76} catch (PhutilJSONParserException $ex) {77throw new PhutilProxyException(78pht('Expected valid JSON response from Disqus account data request.'),79$ex);80}81}8283}848586