abr4xas/oauth2-twitch

This is my package oauth2-twitch

v1.0.0 2022-10-01 13:52 UTC

This package is auto-updated.

Last update: 2024-12-09 10:37:51 UTC


README

Latest Version on Packagist Tests Total Downloads

This package provides Twitch (new version Helix) OAuth 2.0 support for the PHP League's OAuth 2.0 Client.

Installation

You can install the package via composer:

composer require abr4xas/oauth2-twitch

Usage

$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) {
    }
}

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.