PHP code example of dan-rogers / oauth-php

1. Go to this page and download the library: Download dan-rogers/oauth-php 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/ */

    

dan-rogers / oauth-php example snippets


#!/usr/bin/php


use OAuth\OAuth1\OAuth1;
use OAuth\OAuth1\OAuth1Config;

service/auth',
    'oauth_consumer_key' => 'CONSUMER_KEY',
    'consumer_secret' => 'CONSUMER_SECRET',
    'realm' => 'MY_REALM',
    'oauth_signature_method' => OAuth1Config::HMAC_SHA256,
]);

$oauth = new OAuth1($config);
$auth_header = $oauth->generateAuthorization('https://third_party/token_endpoint', 'POST');

// Example usage using PHP CURL

$ch = curl_init();
curl_setopt_array($ch, [
    CURLOPT_URL => 'https://third_party/token_endpoint',
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_HTTPHEADER => [
        'Authorization: ' . $auth_header,
        'Content-Length: 0',
    ],
]);

$response = curl_exec($ch);

composer