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>
-
but how can i set login and password for this service?Wojciech Ka– Wojciech Ka2017-04-20 10:36:08 +00:00Commented Apr 20, 2017 at 10:36
-
Can you explain more details?Khoa Truong– Khoa Truong2017-04-20 12:05:08 +00:00Commented Apr 20, 2017 at 12:05
-
You should read more here: magento.stackexchange.com/a/149927/33057Khoa Truong– Khoa Truong2017-04-20 12:15:03 +00:00Commented 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_authenticationWojciech Ka– Wojciech Ka2017-04-20 12:16:18 +00:00Commented Apr 20, 2017 at 12:16
-
@Wojciech Ka have you found solution?Manisha Vasani– Manisha Vasani2021-02-08 12:23:45 +00:00Commented Feb 8, 2021 at 12:23