markwilson / three-legged-oauth
Oauth app base
Installs: 1 145
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 1
Requires
- symfony/http-foundation: ~2.3
This package is not auto-updated.
Last update: 2021-01-23 09:25:42 UTC
README
Installation
Via composer
Add markwilson/three-legged-oauth
to your composer.json requirements.
php composer.phar install
Usage
<?php require_once 'vendor/autoload.php'; $session = new Symfony\Component\HttpFoundation\Session\Session(); $oAuth = new MarkWilson\ThreeLeggedOAuth( '<base oauth url>', '<consumer key>', '<consumer secret>', $session, '<base app url>' ); if ($oauth->isAuthorised()) { // already authorised, let's connect to the app $response = $oauth->get('<app endpoint>'); echo $response; } elseif ($oauth->isPendingAuthorisation()) { // waiting for authorisation, request access $oauth->getAccessToken(); } else { // no authorisation yet, start request // optionally pass through the callback url here $oauth->requestToken('http://...'); }
Twitter home timeline (very) basic example
<?php require_once 'vendor/autoload.php'; $session = new Symfony\Component\HttpFoundation\Session\Session(); $oauth = new MarkWilson\ThreeLeggedOAuth( 'https://api.twitter.com/oauth/', '<consumer key>', '<consumer secret>', $session, 'https://api.twitter.com/1.1' ); if ($oauth->isAuthorised()) { $response = $oauth->get('/statuses/home_timeline.json'); $jsonDecoded = json_decode($response); foreach ($jsonDecoded as $tweet) { echo $tweet->user->name . ': ' . $tweet->text . '<br />'; } } elseif ($oauth->isPendingAuthorisation()) { $oauth->getAccessToken(); } else { $oauth->requestToken('http://' . $_SERVER['HTTP_HOST'] . '/'); }
Todo list
- Remove Symfony session dependency
- Include interface for persisting tokens between requests