Magento REST API OAuth

Magento REST API OAuth

July 13, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento REST API OAuth

Solving Magento REST API OAuth Issues

Hello! I’m excited to help you navigate through the complexities of setting up the Magento REST API with OAuth authentication. Let’s dive into your issue step by step.

Understanding the Current Problem

You’ve installed Magento on MAMP and successfully installed OAUTH as per the provided StackOverflow link. You’re using Firefox RESTClient to test the OAuth flow, and you’ve created roles and a consumer in Magento, populating their keys accordingly.

However, when posting to http://localhost:8888/store/oauth/initiate?oauth_callback=http://localhost:8888/store/oauth_admin.php, you’re receiving an error:

oauth_problem=signature_invalid&debug_sbs=QiIiTo3WGTZLTOhyIest9B5+l5s=

This indicates a problem with the OAuth signature, which is expected to be invalid since we haven’t yet obtained access tokens.

Analyzing Your PHP Script

You’re using Magento’s official example script for products list retrieval. This script attempts to fetch products via the REST API using admin account and oAuth authorization.

The script initializes by checking if an oauth_token query parameter is present in the $_GET array, and whether a session state of 1 or 2 exists. If neither condition is met and no session state is set, it performs a Request Token GET to obtain temporary credentials for OAuth authorization.

If a state of 1 is found (indicating an Authorization URL response), it sets up the script with the obtained token and redirects to the admin authorization page.

If a state of 2 is found (indicating access token retrieval), it fetches the products list using the oAuthClient object and prints the result. This condition seems to be causing your error.

Debugging the Notice Errors

The Notice: Undefined index errors occur because you’re initially checking for an oauth_token parameter that hasn’t been set in the session state. To resolve this, initialize $_SESSION['state'] = 0; at the beginning of your script to avoid these notices.

Addressing the OAuthException

The main OAuthException indicates a 401 status code (Unauthorized), which means there was an invalid authorization attempt. Let’s analyze the error details:

oauth_problem=signature_invalid&debug_sbs=c3Pb0LJa26al02LJh9hSubXlBs8=

This suggests that the OAuth signature provided in the request is not valid, which is expected since we haven’t yet obtained access tokens.

The debug_sbs parameter contains a Base64-encoded string. Let’s decode it:

echo "c3Pb0LJa26al02LJh9hSubXlBs8=" | base64 -d

This will output the debug information, which can help identify what went wrong in your OAuth signature generation.

Solving the Signature Issue

The key to solving this issue lies in correctly generating and validating the OAuth signatures. This involves:

  1. Obtaining Request Tokens: You need to make a GET request to http://localhost:8888/store/oauth/initiate?oauth_callback=http://localhost:8888/store/oauth_admin.php to obtain your Request Token pair.

  2. Authorizing the Request Tokens: Redirect to the admin authorization URL (http://localhost:8888/store/admin/oAuth_authorize?oauth_token=Your_Request_Token) and grant permission for the application to access your Magento store data.

  3. Obtaining Access Tokens: Make a POST request to http://localhost:8888/store/oauth/token with the necessary parameters (including your Request Token Secret, obtained from Step 1) to obtain your Access Token pair.

  4. Generating Signatures: Use the generated Access Token and Token Secret to sign your API requests using the HMAC-SHA1 algorithm (OAUTH_SIG_METHOD_HMACSHA1). Make sure you’re passing all required parameters (including oauth_consumer_key, oauth_nonce, oauth_signature_method, oauth_timestamp, and your custom request parameters) in the signature generation process.

  5. Validating Signatures: Ensure that Magento validates your signatures correctly by checking if it matches the expected value calculated on its end.

Conclusion

Setting up Magento REST API with OAuth authentication involves a complex authorization flow, including obtaining Request Tokens, authorizing them, and using Access Tokens to make signed API requests.

Remember to thoroughly validate each step of the process, especially the signature generation and validation. If you’re still encountering issues after following these steps, consider checking your Magento version compatibility with OAuth and ensuring that your server environment is configured correctly for PHP’s OAuth library.

For a comprehensive guide on setting up Magento REST API, I recommend checking out our detailed blog post at Laravel Company. It covers the entire setup process with code examples and best practices.

Don’t hesitate to reach out if you have any further questions! Happy coding!

Catalog Database API Admin

Our network