depotwarehouse/oauth2-twitch
最新稳定版本:1.3.3
Composer 安装命令:
composer require depotwarehouse/oauth2-twitch
包简介
A Twitch provider for league/oauth2-client
README 文档
README
This is a package to integrate twitch.tv authentication with the OAuth2 client library by The League of Extraordinary Packages.
To install, use composer:
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:
$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.
Note: The provider uses the "user_read" scope by default. If you pass other scopes, and want the ->getResourceOwner() method to work, you will need to ensure the "user_read" scope is used.
if (isset($_GET['code']) && $_GET['code']) { $token = $this->provider->getAccessToken("authorization_code", [ 'code' => $_GET['code'] ]); // Returns an instance of Depotwarehouse\OAuth2\Client\Twitch\Entity\TwitchUser $user = $this->provider->getResourceOwner($token); $user->getDisplayName(); $user->getId() $user->getType(); $user->getBio(); $user->getEmail(); $user->getPartnered();
Testing
You can quickly test that the package works by adding client information (from your twitch.tv account) to config/config.php
and then starting up a php server
cd test/
php -S localhost:8000
Now, navigating to http://localhost:8000 should present an OAuth flow and then dump your user information.
统计信息
- 总下载量: 118.95k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 18
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-02-02