Sample code for 30+ languages & platforms
PHP

Generate OAuth 1.0 Signature

Demonstrates how to generate an OAuth 1.0 signature.

Chilkat PHP Downloads

Chilkat2 PHP
<?php

use Chilkat2\OAuth1;

$success = false;

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

$success = false;

$oauth = new OAuth1();

// Set input parameters:
$oauth->OauthVersion = '1.0';
$oauth->OauthMethod = 'GET';
$oauth->OauthUrl = 'http://echo.lab.madgex.com/echo.ashx';
$oauth->ConsumerKey = 'key';
$oauth->ConsumerSecret = 'secret';
$oauth->Token = 'accesskey';
$oauth->TokenSecret = 'accesssecret';
$oauth->Nonce = '01020304050607080102030405060708';
$oauth->Timestamp = '1441659763';
// Can be "HMAC-SHA1", "HMAC-SHA256", "RSA-SHA1", or "RSA-SHA2"
$oauth->SignatureMethod = 'HMAC-SHA256';

try {
    $oauth->Generate();
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

// Examine the various outputs:

echo $oauth->QueryString, "\n";
echo $oauth->BaseString, "\n";
echo $oauth->HmacKey, "\n";
echo $oauth->Signature, "\n";
echo $oauth->EncodedSignature, "\n";
echo $oauth->AuthorizationHeader, "\n";
echo $oauth->GeneratedUrl, "\n";