xiabin / oauth2-sinaweibo
Sina Weibo OAuth 2.0 Client Provider for The PHP League OAuth2-Client
v1.0.1
2016-07-04 08:27 UTC
Requires
- php: >=5.5.0
- league/oauth2-client: ~1.0
Requires (Dev)
- mockery/mockery: ~0.9
- phpunit/phpunit: ~4.0
- squizlabs/php_codesniffer: ~2.0
This package is not auto-updated.
Last update: 2025-01-04 20:57:21 UTC
README
这个组件基于 PHP League's OAuth 2.0 Client.
安装
用composer安装:
composer require xiabin/oauth2-sinaweibo
用例
获取token
$provider = new Xiabin\OAuth2\Client\Provider\SinaWeibo([ 'clientId' => '{sinaweibo-client-id}', 'clientSecret' => '{sinaweibo-client-secret}', 'redirectUri' => 'https://example.com/callback-url', ]); if (!isset($_GET['code'])) { //如果没有code就去获取 $authUrl = $provider->getAuthorizationUrl(); $_SESSION['oauth2state'] = $provider->getState(); header('Location: '.$authUrl); exit; //判断state与之前使用的是否一致 } elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) { unset($_SESSION['oauth2state']); exit('Invalid state'); } else { //获取accesstoken $token = $provider->getAccessToken('authorization_code', [ 'code' => $_GET['code'] ]); ... }
测试
$ ./vendor/bin/phpunit
License
The MIT License (MIT). Please see License File for more information.