Use of undefined constant OAUTH_AUTH_TYPE_URI

Use of undefined constant OAUTH_AUTH_TYPE_URI

October 15, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Use of undefined constant OAUTH_AUTH_TYPE_URI

Fixing “Use of undefined constant OAUTH_AUTH_TYPE_URI” Error for Magento API Connection

You’re facing an undefined constant error while trying to connect to the Magento API using OAuth. This issue is quite common due to misconfigured PHP settings or incorrect library usage.

Understanding the Error

The error occurs because the OAUTH_AUTH_TYPE_URI constant is not defined in your current PHP environment. The oauth extension for PHP requires this constant to be set properly.

Verifying PHP Settings

Before proceeding, ensure that the oauth.so extension is enabled in your php.ini file:

;extension=oauth.so

Remove the semicolon (;) before extension and save the changes. Then restart Apache or the web server for the changes to take effect.

Installing the Correct Library

You’re on the right track with using Composer to install the Lusitanian OAuth library. However, the version you specified might be causing issues:

{
    "require": {
        "lusitanian/oauth": "1.0.*@dev"
    }
}

The @dev tag is likely causing conflicts with your current PHP environment.

Instead, use a stable release version like this:

{
    "require": {
        "lusitanian/oauth": "^1.0"
    }
}

Replace the version number according to the latest stable release available on composer.org.

After updating your composer.json file, run composer update in your terminal to install the updated library.

Defining Constants Correctly

The error occurs because you’re trying to use a constant that hasn’t been defined. The oauth extension provides these constants by default when it’s loaded correctly.

However, if you still face issues after checking all the settings above, you can define the constants manually:

define('OAUTH_AUTH_TYPE_URI', 1);
define('OAUTH_AUTH_TYPE_AUTHORIZATION', 2);

Add this code to your PHP script before the line where the OAuth object is created. This should resolve the undefined constant error.

Conclusion

The “undefined constant” error usually arises from a misconfiguration in PHP settings or incorrect library versions. Make sure you’ve enabled the oauth extension, installed the correct library version using Composer, and defined the constants correctly if needed.

Remember to restart Apache or your web server after changing php.ini settings for them to take effect.

If you still face issues after following these steps, consider reviewing your Magento API setup according to the official documentation at https://devdocs.magento.com/guides/m1x/api/rest/introduction.html.

Feel free to explore our blog for more advanced Magento development topics and best practices: https://laravelcompany.com/blog

Database API Extensions Configuration

Our network