PHP Classes

ohmy-auth: Obtain authorization to access APIs using OAuth

Recommend this page to a friend!
  Info   View files Example   View files View files (48)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-09 (4 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 452 All time: 6,148 This week: 120Up
Version License PHP version Categories
ohmy-auth 0.0.16BSD License5.3PHP 5, User Management, Web services
Description 

Author

This package can Obtain authorization to access APIs using OAuth.

It implements the OAuth authorization process to obtain tokens from servers that support either OAuth 1.0a and OAuth 2.0 by the means of a chained function calls.

It supports sending either 2 legged and 3 legged requests.

When the authorization tokens are obtained, it calls a given callback function for further processing by the application.

Picture of Daniel
Name: Daniel <contact>
Classes: 1 package by
Country: United States United States

Example

<?php require_once __DIR__ . '/../vendor/autoload.php';

/*
 * Copyright (c) 2014, Yahoo! Inc. All rights reserved.
 * Copyrights licensed under the New BSD License.
 * See the accompanying LICENSE file for terms.
 */

use ohmy\Auth2;

# initialize 3-legged oauth
$facebook = Auth2::legs(3)
                 ->
set(array(
                   
'id' => 'your client id',
                   
'secret' => 'your client secret',
                   
'redirect' => 'your redirect uri',
                   
'scope' => 'read_stream'
                
))

                
# oauth flow
                
->authorize('https://www.facebook.com/dialog/oauth')
                 ->
access('https://graph.facebook.com/oauth/access_token')
                 ->
finally(function($data) use(&$access_token) {
                    
$access_token = $data['access_token'];
                 });

# test GET call
$facebook->GET("https://graph.facebook.com/me/home?access_token=$access_token")
         ->
then(function($response) {
             echo
'<pre>';
            
var_dump($response->json());
             echo
'</pre>';
         });



Details

ohmy-auth Build Status Scrutinizer Quality Score License

ohmy-auth (Oma) is a PHP library that simplifies OAuth into a fluent interface:

use ohmy\Auth1;
Auth1::legs(2)
     ->set('key', 'key')
     ->set('secret', 'secret')
     ->request('http://term.ie/oauth/example/request_token.php')
     ->access('http://term.ie/oauth/example/access_token.php')
     ->GET('http://term.ie/oauth/example/echo_api.php')
     ->then(function($data) {
         # got data
     });

Dependencies

Oma only requires PHP (>= 5.3) and the usual extensions for Curl (`curl_init()`, `curl_setopt()`, etc), JSON (`json_encode()`, `json_decode()`) and sessions (`session_start()`, `session_destroy()`).

Installing with Composer

The best way to install Oma is via Composer. Just add `ohmy/auth` to your project's `composer.json` and run `composer install`. eg:

{
    "require": {
        "ohmy/auth": "*"
    }
}

Installing manually

If you prefer not to use Composer, you can download an archive or clone this repo and put `src/ohmy` into your project setup.

Two-Legged OAuth 1.0a

use ohmy\Auth1;

# do 2-legged oauth
$termie = Auth1::legs(2)
               # configuration
               ->set('key', 'key')
               ->set('secret', 'secret')
               # oauth flow
               ->request('http://term.ie/oauth/example/request_token.php')
               ->access('http://term.ie/oauth/example/access_token.php');

# api call
$termie->GET('http://term.ie/oauth/example/echo_api.php')
       ->then(function($data) {
           # got data
       });

Three-Legged OAuth 1.0a

Note: This requires sessions in order to save data between redirects. This will not work properly without sessions!

use ohmy\Auth1;

# do 3-legged oauth
$tumblr = Auth1::legs(3)
               # configuration
               ->set(array(
                    'consumer_key'    => 'your_consumer_key',
                    'consumer_secret' => 'your_consumer_secret',
                    'callback'        => 'your_callback_url'
               ))
               # oauth flow
               ->request('http://www.tumblr.com/oauth/request_token')
               ->authorize('http://www.tumblr.com/oauth/authorize')
               ->access('http://www.tumblr.com/oauth/access_token');

# access tumblr api      
$tumblr->GET('https://api.tumblr.com/v2/user/info')
       ->then(function($data) {
           # got user data
       });

Three-Legged OAuth 2.0

use ohmy\Auth2;

# do 3-legged oauth
$github = Auth2::legs(3)
               # configuration
               ->set(array(
                    'id'       => 'your_github_client_id',
                    'secret'   => 'your_github_client_secret',
                    'redirect' => 'your_redirect_uri'
               ))
               # oauth flow
               ->authorize('https://github.com/login/oauth/authorize')
               ->access('https://github.com/login/oauth/access_token')
               ->finally(function($data) use(&$access_token) {
                   $access_token = $data['access_token'];
               });

# access github api
$github->GET("https://api.github.com/user?access_token=$access_token", null, array('User-Agent' => 'ohmy-auth'))
       ->then(function($data) {
           # got user data
       });

More examples

- Facebook - Fitbit - GitHub - Google+ - Instagram - LinkedIn - Live - Tumblr - Twitter - Yahoo

Licenses

- __PHP license__: PHP License - __ohmy-auth__: New BSD License.


  Files folder image Files  
File Role Description
Files folder imageexamples (11 files)
Files folder imagesrc (1 directory)
Files folder imagetests (5 files)
Files folder imagevendor (1 file, 1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. Auxiliary data
Accessible without login Plain text file phpunit.oauth1.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Auxiliary data

  Files folder image Files  /  examples  
File Role Description
  Accessible without login Plain text file facebook.php Example Example script
  Accessible without login Plain text file fitbit.php Example Example script
  Accessible without login Plain text file github.php Example Example script
  Accessible without login Plain text file google.php Example Example script
  Accessible without login Plain text file instagram.php Example Example script
  Accessible without login Plain text file linkedin.php Example Example script
  Accessible without login Plain text file live.php Example Example script
  Accessible without login Plain text file term.ie.php Example Example script
  Accessible without login Plain text file tumblr.php Example Example script
  Accessible without login Plain text file twitter.php Example Example script
  Accessible without login Plain text file yahoo.php Example Example script

  Files folder image Files  /  src  
File Role Description
Files folder imageohmy (2 files, 4 directories)

  Files folder image Files  /  src  /  ohmy  
File Role Description
Files folder imageAuth (2 files)
Files folder imageAuth1 (1 file, 2 directories)
Files folder imageAuth2 (1 file, 1 directory)
Files folder imageComponents (2 files, 2 directories)
  Plain text file Auth1.php Class Class source
  Plain text file Auth2.php Class Class source

  Files folder image Files  /  src  /  ohmy  /  Auth  
File Role Description
  Plain text file Flow.php Class Class source
  Plain text file Promise.php Class Class source

  Files folder image Files  /  src  /  ohmy  /  Auth1  
File Role Description
Files folder imageFlow (2 files, 2 directories)
Files folder imageSecurity (1 file)
  Plain text file Auth1Flow.php Class Class source

  Files folder image Files  /  src  /  ohmy  /  Auth1  /  Flow  
File Role Description
Files folder imageThreeLegged (3 files)
Files folder imageTwoLegged (2 files)
  Plain text file ThreeLegged.php Class Class source
  Plain text file TwoLegged.php Class Class source

  Files folder image Files  /  src  /  ohmy  /  Auth1  /  Flow  /  ThreeLegged  
File Role Description
  Plain text file Access.php Class Class source
  Plain text file Authorize.php Class Class source
  Plain text file Request.php Class Class source

  Files folder image Files  /  src  /  ohmy  /  Auth1  /  Flow  /  TwoLegged  
File Role Description
  Plain text file Access.php Class Class source
  Plain text file Request.php Class Class source

  Files folder image Files  /  src  /  ohmy  /  Auth1  /  Security  
File Role Description
  Plain text file Signature.php Class Class source

  Files folder image Files  /  src  /  ohmy  /  Auth2  
File Role Description
Files folder imageFlow (1 file, 1 directory)
  Plain text file Auth2Flow.php Class Class source

  Files folder image Files  /  src  /  ohmy  /  Auth2  /  Flow  
File Role Description
Files folder imageThreeLegged (2 files)
  Plain text file ThreeLegged.php Class Class source

  Files folder image Files  /  src  /  ohmy  /  Auth2  /  Flow  /  ThreeLegged  
File Role Description
  Plain text file Access.php Class Class source
  Plain text file Authorize.php Class Class source

  Files folder image Files  /  src  /  ohmy  /  Components  
File Role Description
Files folder imageHttp (1 directory)
Files folder imageSession (1 file)
  Plain text file Http.php Class Class source
  Plain text file Session.php Class Class source

  Files folder image Files  /  src  /  ohmy  /  Components  /  Http  
File Role Description
Files folder imageCurl (2 files)

  Files folder image Files  /  src  /  ohmy  /  Components  /  Http  /  Curl  
File Role Description
  Plain text file Request.php Class Class source
  Plain text file Response.php Class Class source

  Files folder image Files  /  src  /  ohmy  /  Components  /  Session  
File Role Description
  Plain text file PHPSession.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Accessible without login Plain text file Auth1Test.php Test Unit test script
  Accessible without login Plain text file Auth2Test.php Test Unit test script
  Accessible without login Plain text file bootstrap.php Aux. Unit test script
  Accessible without login Plain text file PromiseTest.php Test Unit test script
  Accessible without login Plain text file SignatureTest.php Test Unit test script

  Files folder image Files  /  vendor  
File Role Description
Files folder imagecomposer (5 files)
  Accessible without login Plain text file autoload.php Aux. Auxiliary script

  Files folder image Files  /  vendor  /  composer  
File Role Description
  Accessible without login Plain text file autoload_classmap.php Aux. Auxiliary script
  Accessible without login Plain text file autoload_namespaces.php Aux. Auxiliary script
  Accessible without login Plain text file autoload_psr4.php Aux. Auxiliary script
  Plain text file autoload_real.php Class Auxiliary script
  Plain text file ClassLoader.php Class Auxiliary script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:452
This week:0
All time:6,148
This week:120Up