I've created REST API in Magento2 but everyone can use it. How can I add basic auth to my API?
1 Answer
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>
-
-
-
You should read more here: magento.stackexchange.com/a/149927/33057 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 Apr 20, 2017 at 12:16
-