Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple PHP and oAuth Library [closed]

Tags:

php

oauth

I'm looking for a basic oAuth library for PHP, something that I can just pass a consumer key, a secret key, and a URL to request the token, (and a callback) where it will just return an oAuth Token. The main feature it needs is to be useable accross various social networks. currently I have a massive wrapper for Twitter, a massive wrapper for facebook and another for Linked in etc, which could be replaced with one function for each site, and a basic oAuth site.

like image 775
maccard Avatar asked Sep 05 '11 13:09

maccard


2 Answers

There are no such library at the moment. You have the oauth-php and oauth2-php library but they're not "simple", the good part is they manage their token themselves. They don't like overlong tokens (like Yahoo's) which can be a big problem.

Also, some functions of the Microsoft API are not available in their 5.0 version anymore, meaning you have to use their old API which implement their own Oauth protocol (all oauth_* parameters are named wrap_*).

Edit: you can check the HybridAuth project which implements the login part (not the whole APIs) but should give you a good starter.

like image 62
Arkh Avatar answered Sep 28 '22 14:09

Arkh


I actually came across this question myself and ended up building an OAuth library after looking at all the choices I had. Here's some sample code for calling Twitter's API:

use ohmy\Auth1;

# start a session to save oauth data in-between redirects
session_start();

# initialize 3-legged oauth
$twitter = Auth1::init(3);

# configuration
$twitter->set('key', 'your consumer key')
        ->set('secret', 'your consumer secret')
        ->set('callback', 'your callback url')
        ->request('https://api.twitter.com/oauth/request_token')
        ->authorize('https://api.twitter.com/oauth/authorize')
        ->access('https://api.twitter.com/oauth/access_token')
        ->finally(session_destroy);

# test GET call
$twitter->GET('https://api.twitter.com/1.1/statuses/home_timeline.json', array('count' => 5))
        ->then(function($response) {
            echo '<pre>';
            var_dump($response->json());
            echo '</pre>';
        });

The library works with Twitter, Facebook, and LinkedIn. You can check it out at: https://github.com/sudocode/ohmy-auth

like image 28
sudocoder Avatar answered Sep 28 '22 16:09

sudocoder