PHP code example of estebanmatias92 / ohmy-auth

1. Go to this page and download the library: Download estebanmatias92/ohmy-auth library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

estebanmatias92 / ohmy-auth example snippets


use ohmy\Auth;

$credentials = array(
    'key'    => 'key',
    'secret' => 'secret'
);

Auth::init($credentials)
    ->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
    });

use ohmy\Auth;

# configuration
$credentials = array(
    'key'    => 'key',
    'secret' => 'secret'
);

# do 2-legged oauth
$termie = Auth::init($credentials)
              # 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
       });

use ohmy\Auth;

# configuration
$credentials = array(
    'consumer_key'    => 'your_consumer_key',
    'consumer_secret' => 'your_consumer_secret',
    'callback'        => 'your_callback_url'
);

# do 3-legged oauth
$tumblr = Auth::init($credentials)
               # 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
       });

use ohmy\Auth;

# configuration
$credentials = array(
    'id'       => 'your_github_client_id',
    'secret'   => 'your_github_client_secret',
    'redirect' => 'your_redirect_uri'
);

# do 3-legged oauth
$github = Auth::init($credentials)
              # oauth flow
              ->authorize('https://github.com/login/oauth/authorize')
              ->access('https://github.com/login/oauth/access_token')
              # save 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
       });