todomove / oauth2-todoist
此包已被废弃,不再维护。没有建议的替代包。
Todoist.com的league/oauth2-client提供者
0.1.0
2016-10-27 20:04 UTC
Requires
- php: >=5.5
- league/oauth2-client: ~1.4
This package is auto-updated.
Last update: 2023-02-04 13:14:01 UTC
README
此包为PHP League的OAuth 2.0客户端提供TodoistOauth 2.0支持。
安装
要安装,请使用composer
composer require todomove/oauth2-todoist
用法
用法与The League的OAuth客户端相同,使用TodoMove\OAuth2\Client\Provider\Todoist
作为提供者。
授权码流程
$provider = new TodoMove\OAuth2\Client\Provider\Todoist([ 'clientId' => '{client-id}', 'clientSecret' => '{client-secret}', 'redirectUri' => 'https://example.com/callback-url' ]); if (!isset($_GET['code'])) { // If we don't have an authorization code then get one $authUrl = $provider->getAuthorizationUrl(); $_SESSION['oauth2state'] = $provider->state; header('Location: '.$authUrl); exit; // Check given state against previously stored one to mitigate CSRF attack } elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) { unset($_SESSION['oauth2state']); exit('Invalid state'); } else { // Try to get an access token (using the authorization code grant) $token = $provider->getAccessToken('authorization_code', [ 'code' => $_GET['code'] ]); // Use this to interact with an API on the users behalf echo $token->getToken(); }