-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Commit for the first release of the oauth2-twitch package.
- Loading branch information
0 parents
commit 6ce0f1d
Showing
7 changed files
with
456 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.idea/ | ||
vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
Twitch provider for league/oauth2-client | ||
========================================= | ||
|
||
This is a package to integrate Battle.net authentication with the [OAuth2 client library](https://github.com/thephpleague/oauth2-client) by | ||
[The League of Extraordinary Packages](http://thephpleague.com). | ||
|
||
To install, use composer: | ||
|
||
```bash | ||
composer require depotwarehouse/oauth2-twitch | ||
``` | ||
|
||
Usage is the same as the league's OAuth client, using `\Depotwarehouse\OAuth2\Client\Twitch\Provider\Twitch` as the provider. | ||
For example: | ||
|
||
```php | ||
$provider = new \Depotwarehouse\OAuth2\Client\Twitch\Provider\Twitch([ | ||
'clientId' => "YOUR_CLIENT_ID", | ||
'clientSecret' => "YOUR_CLIENT_SECRET", | ||
'redirectUri' => "http://your-redirect-uri" | ||
]); | ||
``` | ||
|
||
You can also optionally add a `scopes` key to the array passed to the constructor. The available scopes are documented | ||
on the [Twitch API Documentation](https://github.com/justintv/Twitch-API/blob/master/authentication.md). | ||
|
||
> Note: The provider uses the "user_read" scope by default. If you pass other scopes, and want the ->getUserDetails() method | ||
to work, you will need to ensure the "user_read" scope is used. | ||
|
||
```php | ||
if (isset($_GET['code']) && $_GET['code']) { | ||
$token = $this->provider->getAccessToken("authorizaton_code", [ | ||
'code' => $_GET['code'] | ||
]); | ||
|
||
// Returns an instance of Depotwarehouse\OAuth2\Client\Twitch\Entity\TwitchUser | ||
$user = $this->provider->getUserDetails($token); | ||
|
||
$user->getDisplayName(); | ||
$user->getId() | ||
$user->getType(); | ||
$user->getBio(); | ||
$user->getEmail(); | ||
$user->getPartnered(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "depotwarehouse/oauth2-twitch", | ||
"description": "A Twitch provider for league/oauth2-client", | ||
"authors": [ | ||
{ | ||
"name": "Troy Pavlek", | ||
"email": "troy@depotwarehouse.net" | ||
} | ||
], | ||
"require": { | ||
"league/oauth2-client": "0.7.*" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Depotwarehouse\\OAuth2\\Client\\Twitch\\": "src/" | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
require 'vendor/autoload.php'; | ||
|
||
$provider = new \Depotwarehouse\OAuth2\Client\Twitch\Provider\Twitch([ | ||
'clientId' => "bqzmhb7560sdxx7ixll05hmo53taxwp", | ||
'clientSecret' => "l8z2b6c0ov025fhg1s14v3eosfdut4r", | ||
'redirectUri' => "http://localhost:8000" | ||
]); | ||
|
||
if (isset($_GET['code']) && $_GET['code']) { | ||
$token = $provider->getAccessToken("authorization_code", [ | ||
'code' => $_GET['code'] | ||
]); | ||
|
||
$user = $provider->getUserDetails($token); | ||
var_dump($user); | ||
|
||
|
||
} else { | ||
header('Location: ' . $provider->getAuthorizationUrl()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
namespace Depotwarehouse\OAuth2\Client\Twitch\Entity; | ||
|
||
class TwitchUser | ||
{ | ||
|
||
/** @var string */ | ||
protected $display_name; | ||
/** @var int */ | ||
protected $id; | ||
/** @var string */ | ||
protected $type; | ||
/** @var string */ | ||
protected $bio; | ||
/** @var string */ | ||
protected $email; | ||
/** @var bool */ | ||
protected $partnered; | ||
|
||
public function __construct(array $attributes = array()) { | ||
$this->id = $attributes['_id']; | ||
$this->display_name = $attributes['display_name']; | ||
$this->type = $attributes['type']; | ||
$this->bio = $attributes['bio']; | ||
$this->email = $attributes['email']; | ||
$this->partnered = $attributes['partnered']; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getDisplayName() | ||
{ | ||
return $this->display_name; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getType() | ||
{ | ||
return $this->type; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getBio() | ||
{ | ||
return $this->bio; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getEmail() | ||
{ | ||
return $this->email; | ||
} | ||
|
||
/** | ||
* @return boolean | ||
*/ | ||
public function isPartnered() | ||
{ | ||
return $this->partnered; | ||
} | ||
|
||
} |
Oops, something went wrong.