1

I've created REST API in Magento2 but everyone can use it. How can I add basic auth to my API?

1 Answer 1

1

You need to add: <resource ref="anonymous" />

For example:

vendor/magento/module-search/etc/webapi.xml

<route url="/V1/search" method="GET">
    <service class="Magento\Search\Api\SearchInterface" method="search"/>
    <resources>
        <resource ref="anonymous" />
    </resources>
</route>
5
  • but how can i set login and password for this service? Commented Apr 20, 2017 at 10:36
  • Can you explain more details? Commented Apr 20, 2017 at 12:05
  • You should read more here: magento.stackexchange.com/a/149927/33057 Commented Apr 20, 2017 at 12:15
  • When resource ref is set to anonymous, everyone can send request. I want to set Authorization type to "Basic Auth" which means that before send requst it is necessary to put login and password to request. [link]en.wikipedia.org/wiki/Basic_access_authentication Commented Apr 20, 2017 at 12:16
  • @Wojciech Ka have you found solution? Commented Feb 8, 2021 at 12:23

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.