This package provides Twitch (new version Helix) OAuth 2.0 support for the PHP League's OAuth 2.0 Client.
You can install the package via composer:
composer require abr4xas/oauth2-twitch
$twitch = new \Abr4xas\Oauth2Twitch\Provider\Twitch([
'clientId' => "CLIENT_ID",
'clientSecret' => "CLIENT_SECRET",
'redirectUri' => "http://localhost:8000",
]);
// get the authorization url
$url = $twitch->getAuthorizationUrl();
// get user info
if (isset($_GET['code'])) {
try {
$token = $twitch->getAccessToken("authorization_code", [
'code' => $_GET['code'],
]);
$user = $twitch->getResourceOwner($token);
$userData = $user->toArray();
// get specific info from your user
// $user->getDisplayName();
// $userData->getId()
// $userData->getType();
// $userData->getBio();
// $userData->getEmail();
// $userData->getPartnered();
print("<pre>".print_r($userData, true)."</pre>");
} catch (\League\OAuth2\Client\Provider\Exception\IdentityProviderException $e) {
}
}
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.