2017 © Pedro Peláez
 

library evaoauth

EvaOAuth

image

allovince/evaoauth

EvaOAuth

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 69 Forks
  • 3 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

EvaOAuth

Latest Stable Version License Build Status Coverage Status Scrutinizer Code Quality, (*1)

EvaOAuth provides a standard interface for OAuth1.0 / OAuth2.0 client authorization, it is easy to integrate with any PHP project by very few lines code., (*2)

中文文档, (*3)

Features

  • Standard interface, same code for both OAuth1.0 and OAuth2.0 different workflow, receiving token and user info as same format either.
  • Fully tested
  • Easy to debug, enable debug mode will record every request and response, help you find out problems quickly.
  • Out-of-the-box, already supported most popular websites including Facebook. Twitter, etc.
  • Scalable, integrate a new oauth website just need 3 lines code.

Quick Start

EvaOAuth can be found on Packagist. The recommended way to install this is through composer., (*4)

Edit your composer.json and add:, (*5)

``` json { "require": { "evaengine/eva-oauth": "~1.0" } }, (*6)


And install dependencies: ``` shell curl -sS https://getcomposer.org/installer | php php composer.phar install

Let's start a example of Facebook Login, if you have already have a Facebook developer account and created an app, prepare a request.php as below:, (*7)

``` php $service = new Eva\EvaOAuth\Service('Facebook', [ 'key' => 'You Facebook App ID', 'secret' => 'You Facebook App Secret', 'callback' => 'http://localhost/EvaOAuth/example/access.php' ]); $service->requestAuthorize();, (*8)


Run request.php in browser, will be redirected to Facebook authorization page. After user confirm authorization, prepare the access.php for callback: ``` php $token = $service->getAccessToken();

Once access token received, we could use access token to visit any protected resources., (*9)

``` php $httpClient = new Eva\EvaOAuth\AuthorizedHttpClient($token); $response = $httpClient->get('https://graph.facebook.com/me');, (*10)


That's it, more usages please check [examples](https://github.com/AlloVince/EvaOAuth/tree/master/examples) and [wiki](https://github.com/AlloVince/EvaOAuth/wiki). ## Providers EvaOAuth supports most popular OAuth services as below: - OAuth2.0 - Douban - Facebook - Tencent - Weibo - OAuth1.0 - Twitter Creating a custom provider require only few lines code, for OAuth2 sites: ``` php namespace YourNamespace; class Foursquare extends \Eva\EvaOAuth\OAuth2\Providers\AbstractProvider { protected $authorizeUrl = 'https://foursquare.com/oauth2/authorize'; protected $accessTokenUrl = 'https://foursquare.com/oauth2/access_token'; }

Then register to service and create instance:, (*11)

``` php use Eva\EvaOAuth\Service; Service::registerProvider('foursquare', 'YourNamespace\Foursquare'); $service = new Service('foursquare', [ 'key' => 'Foursquare App ID', 'secret' => 'Foursquare App Secret', 'callback' => 'http://somecallback/' ]);, (*12)


## Storage In OAuth1.0 workflow, we need to store request token somewhere, and use request token exchange for access token. EvaOAuth use [Doctrine\Cache](https://github.com/doctrine/cache) as storage layer. If no configuration, default storage layer use file system to save data, default path is EvaOAuth/tmp. Feel free to change file storage path before `Service` start: ``` php Service::setStorage(new Doctrine\Common\Cache\FilesystemCache('/tmp'));

Or use other storage such as Memcache:, (*13)

``` php $storage = new \Doctrine\Common\Cache\MemcacheCache(); $storage->setMemcache(new \Memcache()); Service::setStorage($storage);, (*14)


## Events Support EvaOAuth defined some events for easier injection which are: - BeforeGetRequestToken: Triggered before get request token. - BeforeAuthorize: Triggered before redirect to authorize page. - BeforeGetAccessToken: Triggered before get access token. For example, if we want to send an additional header before get access token: ``` php $service->getEmitter()->on('beforeGetAccessToken', function(\Eva\EvaOAuth\Events\BeforeGetAccessToken $event) { $event->getRequest()->addHeader('foo', 'bar'); });

Implementation Specification

EvaOAuth based on amazing http client library Guzzle, use fully OOP to describe OAuth specification., (*15)

Refer wiki for details:, (*16)

Debug and Logging

Enable debug mode will log all requests & responses., (*17)

php $service->debug('/tmp/access.log');, (*18)

Make sure PHP script have permission to write log path., (*19)

API References

Run phpdoc will generate API references under docs/., (*20)

, (*21)

Join My Telegram Group, (*22)

The Versions

13/06 2015

dev-master

9999999-dev http://avnpc.com/

EvaOAuth is an abstract interface to setup OAuth client, both support OAuth1.0a / OAuth2.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

13/06 2015

1.0.2

1.0.2.0 http://avnpc.com/

EvaOAuth is an abstract interface to setup OAuth client, both support OAuth1.0a / OAuth2.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

01/05 2015

1.0.1

1.0.1.0 http://avnpc.com/

EvaOAuth is an abstract interface to setup OAuth client, both support OAuth1.0a / OAuth2.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

30/04 2015

1.0.0

1.0.0.0 http://avnpc.com/

EvaOAuth is an abstract interface to setup OAuth client, both support OAuth1.0a / OAuth2.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

21/04 2015

dev-feature/refactoring

dev-feature/refactoring http://avnpc.com/

EvaOAuth is an abstract interface to setup OAuth client, both support OAuth1.0a / OAuth2.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires