3

I am using Magento 2.4.4 with xampp in my local.Have created extension integration token and added acl for newly created custom rest api resource. when i was provide access Token in my rest api as authorization bearer token , still service responded as 401 and error message "The consumer isn't authorized to access %resources".

3 Answers 3

7

I Guess you should enable below config setting,

Allow OAuth Access Tokens to be used as standalone Bearer tokens

Stores > Configuration > Services > OAuth > Consumer Settings > Allow OAuth Access Tokens to be used as standalone Bearer tokens option to Yes

You can also enable this setting from the CLI by running the following command:

bin/magento config:set oauth/consumer/enable_integration_as_bearer 1

6

My guess... There could be several reasons why you are receiving a 401 unauthorized error message when trying to access your custom REST API resource in Magento 2.4.4. Here are some potential solutions:

Verify that your integration token is set up correctly: Make sure that you have created the integration token correctly and that it has the necessary permissions to access the resources you are trying to access. To do this, go to System > Integration in your Magento admin panel and ensure that the integration is active and has the correct permissions.

Check that your ACL is set up correctly: Make sure that you have set up the necessary ACL (Access Control List) rules for your custom REST API resource. To do this, go to System > Permissions > User Roles in your Magento admin panel and ensure that the role associated with your integration token has the correct permissions.

Check that your API endpoint is correct: Double-check that you are using the correct URL for your custom REST API resource. Make sure that the URL is correct and that you are using the correct HTTP method (GET, POST, PUT, etc.).

Verify that the authorization header is correctly formatted: Make sure that you are passing the authorization header correctly with your access token. The authorization header should be in the following format: Authorization: Bearer {access_token}.

Clear your cache: Sometimes cache issues can cause authorization problems. Try clearing your Magento cache and see if that resolves the issue.

Check your server logs: If none of the above solutions work, check your server logs to see if there are any error messages that can help you identify the problem.

1

When creating the integration, did you select the appropriate resources that it can access (customer for example)? Magento provided a guide for creating integrations here:

  • Log in to Admin and click System > Extensions > Integrations to display the Integrations page.
  • Click Add New Integration to display the New Integration page.
  • Enter a unique name for the integration in the Name field. Then enter your admin password in the Your Password field. Leave all other fields blank.
  • Click the API tab. Select the Magento resources the integration can access. You can select all resources, or select a custom list. Make sure you include Customer resource here, or select "All".
  • Click Save to save your changes and return to the Integrations page.
  • Click the Activate link in the grid that corresponds to the newly-created integration.
  • Click Allow. A dialog box containing the access token/secret values etc should appear.

You may also need to allow bearer tokens via config setting. Info here:

bin/magento config:set oauth/consumer/enable_integration_as_bearer 1

Make sure you flush caches after saving this config setting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.