oAuth 1.0 REST API with Magento 1.9, how to get oauth_signature like postman does?

oAuth 1.0 REST API with Magento 1.9, how to get oauth_signature like postman does?

August 17, 2026 · Illustrated author avatarBy Stefan Bogdanescu
oAuth 1.0 REST API with Magento 1.9, how to get oauth_signature like postman does?

Title: Implementing OAuth 1.0 REST API Authentication for Magento 1.9

As a senior developer specializing in e-commerce platforms like Magento, I often encounter challenges when integrating external systems with the legacy REST APIs of earlier versions such as Magento 1.9. One common issue is handling authentication, particularly with older protocols like OAuth 1.0. This blog post will guide you through the process of generating the necessary OAuth signature for a GET request to a Magento 1.9 REST API using PHP.

Understanding the OAuth 1.0 Signature Generation Process

Before diving into the code, it’s crucial to understand how the OAuth 1.0 signature is generated. The signature is a hash created from several components:

  1. Consumer Key and Secret: These are your application-specific credentials.
  2. Access Token and Secret: These are obtained during the authorization process and represent a user’s permission level.
  3. Timestamp and Nonce: The timestamp (oauth_timestamp) is the current time in seconds since the Unix epoch, while the nonce (oauth_nonce) is a unique string used to ensure the request hasn’t been tampered with.

The signature is generated by concatenating these components into a Base String and then applying a hash function (HMAC-SHA1 in this case).

The Challenge: Generating the Signature Manually

The provided code snippet from Magento’s documentation attempts to handle the entire OAuth 1.0 flow, including obtaining temporary credentials, authorizing them, and finally making the API request. However, it fails because it doesn’t generate the signature correctly.

A Step-by-Step Solution

To generate the correct signature for a GET request, we’ll create a function that mimics Postman’s behavior:

function generateOAuth1Signature($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret, $timestamp, $nonce) {
    // The Base String components
    $baseString = 'GET&';
    $baseString .= urlencode('https://www.example.com/api/rest/products') . '&';
    $baseString .= urlencode('oauth_consumer_key=' . $consumerKey);
    $baseString .= urlencode('oauth_token=' . $accessToken);
    $baseString .= urlencode('oauth_signature_method=HMAC-SHA1');
    $baseString .= urlencode('oauth_timestamp=' . $timestamp);
    $baseString .= urlencode('oauth_nonce=' . $nonce);
    $baseString .= urlencode('oauth_version=1.0');

    // Create the signing key
    $signingKey = urlencode($consumerSecret) . '&' . urlencode($accessTokenSecret);

    // Apply the HMAC-SHA1 hash and then base64 encode it
    return urlencode(base64_encode(hash_hmac('sha1', $baseString, $signingKey)));
}

Integrating the Signature Generation Function

Now, let’s integrate this function into your API request:

$consumerKey = 'your_consumer_key';
$consumerSecret = 'your_consumer_secret';
$accessToken = 'your_access_token';
$accessTokenSecret = 'your_access_token_secret';
$timestamp = time();
$nonce = hash('sha256', uniqid(rand(), true));

$url = "https://www.example.com/api/rest/products";

// Generate the OAuth signature
$signature = generateOAuth1Signature($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret, $timestamp, $nonce);

$headers = array(
    'Authorization: OAuth oauth_consumer_key="' . $consumerKey . '",oauth_token="' . $accessToken . '",oauth_signature_method="HMAC-SHA1",oauth_timestamp="' . $timestamp . '",oauth_nonce="' . $nonce . '",oauth_version="1.0",oauth_signature="' . $signature . '"',
    'Cache-Control: no-cache',
    'Content-Type: application/json'
);

// Make the GET request using Guzzle (more modern and object-oriented than cURL)
$client = new \GuzzleHttp\Client();
$response = $client->request('GET', $url, ['headers' => $headers]);

// Process the response
$productsList = json_decode($response->getBody()->getContents());
print_r($productsList);

Conclusion

In this blog post, we’ve addressed a common challenge faced when working with Magento 1.9’s REST API and OAuth 1.0 authentication. By understanding the signature generation process and implementing it manually, you can now successfully authenticate your PHP application to access the API without relying on Postman.

Remember, always ensure that your secrets (consumer secret and access token secret) are kept secure and not exposed in your code. If you found this solution helpful, feel free to explore our other tutorials on Magento integration at Laravel Company.

Don’t hesitate to reach out if you have any further questions or need assistance with other aspects of e-commerce development!

Magento 1 Security API Errors

Our network