markwilson/three-legged-oauth

This package is abandoned and no longer maintained. No replacement package was suggested.

Oauth app base

0.1.10 2015-04-06 13:30 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