I'm in the middle of finishing a Magento 2 store for a client. The last I had on my to-do list, was connect Magento to their accounting software through the REST API.
However, apparently there's some serious issue when it comes to the REST API in the Magento installation. No matter what I do I'm always given a "Consumer is not authorized to access %resources" error, such as:
{
"message": "Consumer is not authorized to access %resources",
"parameters": {
"resources": "Magento_Sales::sales"
}
}
I'm using an Access Token created through Admin > System > Integrations. The created Integration has resource access set to ALL.
System:
- CentOS 7
- WHM/cPanel
- PHP 7.3.27
- PHP Handler SuPHP
- Magento 2.4.1
- Webserver: Apache (port 8080)
- Cache: Varnish (port 80)
- SSL: Nginx as reverse proxy for SSL (port 443)
Things I've tried based on similar questions:
- Change PHP handler from CGI to SuPHP (source)
- Enable individual API resource access instead of setting to 'ALL' (source)
- Tested without Varnish between client and server
- Tested without Nginx proxy between client and server
I really can't seem to figure out what I'm doing wrong here. Does anybody have an idea what might be causing this? An option would be to do a fresh installation, but that'd be my very last option as I've been working on this Magento environment (theme, thouuuusands of products, ...) for many months.
Edit 1: Been digging into this a bit more. Seems like the error is being caused in: /vendor/magento/module-webapi/Model/Authorization/TokenUserContext.php
(Don't worry, I won't edit vendor files directly ;-))
Lines:
$authorizationHeaderValue = $this->request->getHeader('Authorization');
if (!$authorizationHeaderValue) {
$this->isRequestProcessed = true;
return;
}
Looks like the Authorization header is missing. They are being set, so I guess something is causing them to be unset or not really being passed to the actual webserver?