Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated API to work with Helix #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/Entity/TwitchUser.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php namespace Depotwarehouse\OAuth2\Client\Twitch\Entity;

use League\OAuth2\Client\Provider\ResourceOwnerInterface;

/**
* Class TwitchUser
* @package Depotwarehouse\OAuth2\Client\Twitch\Entity
*/
class TwitchUser
class TwitchUser implements ResourceOwnerInterface
{
/**
* @var string
Expand Down Expand Up @@ -50,14 +52,15 @@ class TwitchUser
*/
public function __construct(array $attributes = array())
{
$this->id = $attributes['_id'];
// See https://dev.twitch.tv/docs/api/reference#get-users.
$this->id = (int) $attributes['id'];
$this->display_name = $attributes['display_name'];
$this->type = $attributes['type'];
$this->bio = $attributes['bio'];
$this->bio = $attributes['description'];
$this->email = $attributes['email'];
$this->partnered = $attributes['partnered'];
$this->name = $this->username = $attributes['name'];
$this->logo = $attributes['logo'];
$this->partnered = $this->type === 'partnered';
$this->name = $this->username = $attributes['login'];
$this->logo = $attributes['profile_image_url'];
}

/**
Expand Down
43 changes: 32 additions & 11 deletions src/Provider/Twitch.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,32 @@ class Twitch extends AbstractProvider
{

/**
* Api domain
* The domain for authorization.
*
* @var string
*/
public $apiDomain = 'https://api.twitch.tv';
public $authorizationDomain = 'https://id.twitch.tv';

/**
* The path for authorization.
*
* @var string
*/
public $authorizationPath = '/oauth2';

/**
* The domain with resources.
*
* @var string
*/
public $resourceDomain = 'https://api.twitch.tv';

/**
* The path with resources.
*
* @var string
*/
public $resourcePath = '/helix';

public $scopes = [ 'user_read' ];

Expand All @@ -27,7 +48,7 @@ class Twitch extends AbstractProvider
*/
public function getBaseAuthorizationUrl()
{
return $this->apiDomain.'/kraken/oauth2/authorize';
return $this->authorizationDomain.$this->authorizationPath.'/authorize';
}

/**
Expand All @@ -39,7 +60,7 @@ public function getBaseAuthorizationUrl()
*/
public function getBaseAccessTokenUrl(array $params)
{
return $this->apiDomain.'/kraken/oauth2/token';
return $this->authorizationDomain.$this->authorizationPath.'/token';
}

/**
Expand All @@ -51,7 +72,7 @@ public function getBaseAccessTokenUrl(array $params)
*/
public function getResourceOwnerDetailsUrl(AccessToken $token)
{
return $this->getAuthenticatedUrlForEndpoint('/kraken/user', $token);
return $this->resourceDomain.$this->resourcePath.'/users?oauth_token='.$token->getToken();
}

/**
Expand All @@ -63,7 +84,7 @@ public function getResourceOwnerDetailsUrl(AccessToken $token)
*/
public function getAuthenticatedUrlForEndpoint($endpoint, AccessToken $token)
{
return $this->apiDomain.$endpoint.'?oauth_token='.$token->getToken();
return $this->authorizationDomain.$endpoint.'?oauth_token='.$token->getToken();
}

/**
Expand All @@ -74,7 +95,7 @@ public function getAuthenticatedUrlForEndpoint($endpoint, AccessToken $token)
*/
public function getUrlForEndpoint($endpoint)
{
return $this->apiDomain.$endpoint;
return $this->authorizationDomain.$endpoint;
}

/**
Expand Down Expand Up @@ -139,7 +160,7 @@ protected function createResourceOwner(array $response, AccessToken $token)
*/
protected function getDefaultHeaders()
{
return ['Client-ID' => $this->clientId, 'Accept' => 'application/vnd.twitchtv.v5+json'];
return ['Client-ID' => $this->clientId];
}

/**
Expand All @@ -149,9 +170,9 @@ protected function getDefaultHeaders()
* @return array
*/
protected function getAuthorizationHeaders($token = null) {
if(isset($token))
return ['Authorization' => 'OAuth '.$token->getToken()];
return [];
return $token ? [
'Authorization' => 'Bearer ' . $token->getToken(),
] : [];
}


Expand Down