• Stars
    star
    254
  • Rank 160,264 (Top 4 %)
  • Language
    PHP
  • License
    BSD 3-Clause "New...
  • Created about 11 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

EvaOAuth

Latest Stable Version License Build Status Coverage Status Scrutinizer Code Quality

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.

δΈ­ζ–‡ζ–‡ζ‘£

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.

Edit your composer.json and add:

{
    "require": {
        "evaengine/eva-oauth": "~1.0"
    }
}

And install dependencies:

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:

$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();

Run request.php in browser, will be redirected to Facebook authorization page. After user confirm authorization, prepare the access.php for callback:

$token = $service->getAccessToken();

Once access token received, we could use access token to visit any protected resources.

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

That's it, more usages please check examples and 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:

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:

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

Storage

In OAuth1.0 workflow, we need to store request token somewhere, and use request token exchange for access token.

EvaOAuth use 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:

Service::setStorage(new Doctrine\Common\Cache\FilesystemCache('/tmp'));

Or use other storage such as Memcache:

$storage = new \Doctrine\Common\Cache\MemcacheCache();
$storage->setMemcache(new \Memcache());
Service::setStorage($storage);

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:

$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.

Refer wiki for details:

Debug and Logging

Enable debug mode will log all requests & responses.

$service->debug('/tmp/access.log');

Make sure PHP script have permission to write log path.

API References

Run phpdoc will generate API references under docs/.

Join My Telegram Group

More Repositories

1

EvaThumber

A light-weight url based image transformation php library
PHP
555
star
2

eva-engine

EvaEngine has been rewrote by Phalcon framework and moved to https://github.com/EvaEngine/EvaEngine
PHP
153
star
3

physics_mathematics_skills_for_game_development

γ€ŠζΈΈζˆεΌ€ε‘ηš„ζ•°ε­¦ε’Œη‰©η†γ€‹ι…ε₯—瀺例代码
C++
132
star
4

drone-ci-demo

A Demo to show workflow of Drone CI + GitFlow + Semantic Release + Kubernetes
JavaScript
47
star
5

vim-of-allovince

Vim Of AlloVince
Vim Script
35
star
6

EvaBootstrap

EvaBootstrap is a modify version of Twitter Bootstrap, main change is removing invasive from Twitter Bootstrap. You could use EvaBootstrap in any of your exists project, EvaBootstrap will NOT CHANGE your default css styles.
29
star
7

evaengine-libs-front

EvaEngine Front-end CSS/Js 3rd libs
JavaScript
26
star
8

webapp-startup

A basic web app template by requireJs & jquery mobile
JavaScript
23
star
9

avnpc.content

Markdown raw posts content & comments (use issues) of blog avnpc.com
CSS
15
star
10

Candly

A finance chart lib based on d3js
JavaScript
12
star
11

evandroid

Java
9
star
12

EvaScrapy

Scrapy components for generic crawling
Python
5
star
13

graphql-boot

Maybe the best practice for GraphQL on node.js project.
JavaScript
4
star
14

gimare

Convert any Gist Markdown file into a slide show in minutes
JavaScript
4
star
15

mini-fsm

A js/nodejs minimum Finite State Machine with fully ES6/ES7 support
JavaScript
4
star
16

evaengine-documentation

Documentation of EvaEngine
Python
2
star
17

avnpc

Blog of AlloVince based on EvaEngine
CSS
2
star
18

av2me

An ES6 based NodeJS + ExpressJS Skeleton
JavaScript
2
star
19

Ifso

Maybe a Chinese simple programming language by lex & yacc
C
2
star
20

anti-captcha

Python
1
star
21

EvaXunlei

Just a redirect trick for xunlei vod
PHP
1
star
22

EvaPandoc

A background cli to compile markdown to letax html by pandoc
PHP
1
star
23

web-plus-db-press

Web+DB Press PHP专栏配ε₯—瀺例代码
PHP
1
star
24

yadht

Yet another BitTorrent DHT implementation (BEP 5) by TypeScript
TypeScript
1
star
25

javascript-algorithms

1
star
26

EvaPinyin

A chinese characters to pinyin lib
PHP
1
star
27

avnpc.front

A Server-Side-Render blog frontend based on Next.js / Ant.design / EvaEngine.js
JavaScript
1
star