Simple PHP and oAuth library

I am looking for the oAuth core library for PHP, something that I can just pass in the consumer key, secret key and URL to request a token (and callback), where it just returns the OAuth token, The main feature he needs is - This is to use it in various social networks. I currently have a massive cover for Twitter, a massive wrapper for facebook and another for Linked in, etc., which can be replaced with one function for each site and the base oAuth site.

+6
source share
2 answers

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

In addition, some Microsoft API functions are no longer available in version 5.0, that is, you must use your old API, which implements its own Oauth protocol (all oauth_ * parameters are called wrap _ *).

Edit: You can check out the HybridAuth project, which implements part of the input (not all APIs), but should give you a good starter.

+4
source

I myself came across this question and eventually created the OAuth library, looking at all the options that I had. Here is a sample code to call the Twitter 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 this out: https://github.com/sudocode/ohmy-auth

+1
source

Source: https://habr.com/ru/post/896643/


All Articles