-
Notifications
You must be signed in to change notification settings - Fork 9.4k
The consumer isn't authorized to access %resources. Magento 2.4.5-p1 on staging environment #38426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @nilaykumardeveloper. Thank you for your report.
Join Magento Community Engineering Slack and ask your questions in #github channel. |
Hi @engcom-Bravo. Thank you for working on this issue.
|
@magento give me 2.4-develop instance |
Hi @engcom-Bravo. Thank you for your request. I'm working on Magento instance for you. |
Hi @engcom-Bravo, here is your Magento Instance: https://c323692eebc28d54fed624e12837ba86.instances-prod.magento-community.engineering |
Thank you for reporting and collaboration. Verified the issue on Magento 2.4-develop instance and the issue is reproducible.Kindly refer the attached screenshots. We have given access for all the resources still we are getting the error. Hence Confirming the issue. Thanks. |
✅ Jira issue https://jira.corp.adobe.com/browse/AC-10997 is successfully created for this GitHub issue. |
✅ Confirmed by @engcom-Bravo. Thank you for verifying the issue. |
Sure! If anyone has any suggestions, please let me know. Your input would be greatly appreciated. |
Related issue: #36811 |
HI Guys just wondering if theres any time estimation on this? Kind Regards, |
need a fix on this too |
@engcom-Bravo - has there been any internal development on this issue, is there a workaround? It has completely broken integration with Magento for me, it's a really major bug. |
Looks like issue is related to when your storefront URL is not same as your base url at "All Stores View". |
Same for me on 2.4.5-p8 CE. Base URL is fine but storefront URL throws the error. |
There is not a solution? WIth magento 2.4.7 and 2.4.6 same error. Is really important bug. |
This occurs for all store URLs for me.
Seems insane that this major bug isn't being addressed. This is an open issue, P2 priority, confirmed, reproduced and sitting in high priority backlog for nearly half a year. As a workaround, I hack vendor/magento/module-webapi/Controller/Rest/RequestValidator.php, and add an extra validator:
And then when I make a REST call, I add an extra header in the call:
Obviously this isn't ideal as it's a reusable symmetric cleartext password and bypasses finegrained ACL, but at least it works for now.. |
Any update on this? |
The only workaround I now see is the following. If you use the option 'Allow OAuth Access Tokens to be used as standalone Bearer tokens'. And you trust the integration party. You can bypass the (false negative) exception. I would ask the third party for their IP's and do the following: Inside module-webapi/Controller/Rest/RequestValidator.php change 'checkPermissions()' and add a custom function:
Needless to say; be careful. I do not have tested this a lot. Use at your own risk. |
I had the same issue when upgrading from Magento 2.4.2 to 2.4.7. From what I understand, security has been reinforced in the latest versions, and OAuth tokens can no longer be used as Bearer tokens by default. You need to explicitly change the settings to allow this behavior. |
Summary
In the testing environment, it gives below errors,
}
Its already Yes in: Allow OAuth Access Tokens.
I tried it in PHP script with Integration user as well as bearer token and not working in both scenario. The main thing is that live and local environment looks fine with same code file and DB setup.
So my concern is that, Is any configuration on server can impact on this?
PHP script:
function sign($method, $url, $data, $consumerSecret, $tokenSecret)
{
$url = urlEncodeAsZend($url);
$data = urlEncodeAsZend(http_build_query($data, '', '&'));
$data = implode('&', [$method, $url, $data]);
$secret = implode('&', [$consumerSecret, $tokenSecret]);
return base64_encode(hash_hmac('sha256', $data, $secret, true));
}
function urlEncodeAsZend($value)
{
$encoded = rawurlencode($value);
$encoded = str_replace('%7E', '~', $encoded);
return $encoded;
}
// REPLACE WITH YOUR ACTUAL DATA OBTAINED WHILE CREATING NEW INTEGRATION
$consumerKey = 'XXXXXXXXXXXXXXXXXXXXXXXXXXX';
$consumerSecret = 'XXXXXXXXXXXXXXXXXXXXXXXXXXX';
$accessToken = 'XXXXXXXXXXXXXXXXXXXXXXXXXXX';
$accessTokenSecret = 'XXXXXXXXXXXXXXXXXXXXXXXXXXX';
$method = 'GET';
$url = 'http://xxxx.staging.com/rest/V1/orders/38024';
$data = [
';'oauth_consumer_key' => $consumerKey,
'oauth_nonce' => md5(uniqid(rand(), true)),
'oauth_signature_method' => 'HMAC-SHA256',
'oauth_timestamp' => time(),
'oauth_token' => $accessToken,
'oauth_version' => '1.0',
];
$data['oauth_signature'] = sign($method, $url, $data, $consumerSecret, $accessTokenSecret);
//print_r($data);
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $url,
CURLOPT_HTTPHEADER => [
'Authorization: OAuth ' . http_build_query($data, '', ',')
]
]);
$result = curl_exec($curl);
$orderData = json_decode($result,true);
curl_close($curl);
echo '
?>

POSTMAN:
Examples
`
$consumerKey, 'oauth_nonce' => md5(uniqid(rand(), true)), 'oauth_signature_method' => 'HMAC-SHA256', 'oauth_timestamp' => time(), 'oauth_token' => $accessToken, 'oauth_version' => '1.0', ]; $data['oauth_signature'] = sign($method, $url, $data, $consumerSecret, $accessTokenSecret); //print_r($data); $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $url, CURLOPT_HTTPHEADER => [ 'Authorization: OAuth ' . http_build_query($data, '', ',') ] ]); $result = curl_exec($curl); $orderData = json_decode($result,true); curl_close($curl); echo ' '; ?>`I tried it in the PHP script with the Integration user as well as the bearer token and it did not work in both scenarios. The main thing is that the live and local environment looks fine with the same code file and DB setup.
So my concern is that, Is any configuration on server can impact on this?
Proposed solution
No response
Release note
No response
Triage and priority
The text was updated successfully, but these errors were encountered: