Changeset View
Changeset View
Standalone View
Standalone View
src/applications/auth/adapter/PhutilTwitchAuthAdapter.php
<?php | <?php | ||||
/** | /** | ||||
* Authentication adapter for Twitch.tv OAuth2. | * Authentication adapter for Twitch.tv OAuth2. | ||||
*/ | */ | ||||
final class PhutilTwitchAuthAdapter extends PhutilOAuthAuthAdapter { | final class PhutilTwitchAuthAdapter extends PhutilOAuthAuthAdapter { | ||||
public function getAdapterType() { | public function getAdapterType() { | ||||
return 'twitch'; | return 'twitch'; | ||||
} | } | ||||
public function getAdapterDomain() { | public function getAdapterDomain() { | ||||
return 'twitch.tv'; | return 'twitch.tv'; | ||||
} | } | ||||
public function getAccountID() { | public function getAccountID() { | ||||
return $this->getOAuthAccountData('_id'); | return $this->getOAuthAccountData('id'); | ||||
} | } | ||||
public function getAccountEmail() { | public function getAccountEmail() { | ||||
return $this->getOAuthAccountData('email'); | return $this->getOAuthAccountData('email'); | ||||
} | } | ||||
public function getAccountName() { | public function getAccountName() { | ||||
return $this->getOAuthAccountData('name'); | return $this->getOAuthAccountData('login'); | ||||
} | } | ||||
public function getAccountImageURI() { | public function getAccountImageURI() { | ||||
return $this->getOAuthAccountData('logo'); | return $this->getOAuthAccountData('profile_image_url'); | ||||
} | } | ||||
public function getAccountURI() { | public function getAccountURI() { | ||||
$name = $this->getAccountName(); | $name = $this->getAccountName(); | ||||
if ($name) { | if ($name) { | ||||
return 'http://www.twitch.tv/'.$name; | return 'http://www.twitch.tv/'.$name; | ||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
public function getAccountRealName() { | public function getAccountRealName() { | ||||
return $this->getOAuthAccountData('display_name'); | return $this->getOAuthAccountData('display_name'); | ||||
} | } | ||||
protected function getAuthenticateBaseURI() { | protected function getAuthenticateBaseURI() { | ||||
return 'https://api.twitch.tv/kraken/oauth2/authorize'; | return 'https://id.twitch.tv/oauth2/authorize'; | ||||
} | } | ||||
protected function getTokenBaseURI() { | protected function getTokenBaseURI() { | ||||
return 'https://api.twitch.tv/kraken/oauth2/token'; | return 'https://id.twitch.tv/oauth2/token'; | ||||
} | } | ||||
public function getScope() { | public function getScope() { | ||||
return 'user_read'; | return 'user_read'; | ||||
} | } | ||||
public function getExtraAuthenticateParameters() { | public function getExtraAuthenticateParameters() { | ||||
return array( | return array( | ||||
'response_type' => 'code', | 'response_type' => 'code', | ||||
); | ); | ||||
} | } | ||||
public function getExtraTokenParameters() { | public function getExtraTokenParameters() { | ||||
return array( | return array( | ||||
'grant_type' => 'authorization_code', | 'grant_type' => 'authorization_code', | ||||
); | ); | ||||
} | } | ||||
protected function loadOAuthAccountData() { | protected function loadOAuthAccountData() { | ||||
return id(new PhutilTwitchFuture()) | return id(new PhutilTwitchFuture()) | ||||
->setClientID($this->getClientID()) | ->setClientID($this->getClientID()) | ||||
->setAccessToken($this->getAccessToken()) | ->setAccessToken($this->getAccessToken()) | ||||
->setRawTwitchQuery('user') | ->setRawTwitchQuery('users') | ||||
->resolve(); | ->resolve(); | ||||
} | } | ||||
} | } |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0