소비자는 Magento2 rest API에 대한 % resources에 액세스 할 권한이 없습니다


9

새 고객을 만들고 토큰을 완벽하게 얻었지만 다음과 같은 API에 액세스하려고 할 때

http://myhost.com/index.php/rest/V1/customers/me?Authorization=Bearerhy23vc01x9s1jd2t8gho47g58trllc0b 

오류가 발생했습니다

<?xml version="1.0"?>
<response>
<message>Consumer is not authorized to access %resources</message>
<parameters>
<resources>self</resources>
</parameters>
  <trace>#0 /var/www/myhost.com/public_html/vendor/magento/module-webapi/Controller/Rest/RequestValidator.php(70): Magento\Webapi\Controller\Rest\RequestValidator-&gt;checkPermissions()
#1 /var/www/myhost.com/public_html/vendor/magento/module-webapi/Controller/Rest/InputParamsResolver.php(80): Magento\Webapi\Controller\Rest\RequestValidator-&gt;validate()
#2 /var/www/myhost.com/public_html/vendor/magento/module-webapi/Controller/Rest.php(299): Magento\Webapi\Controller\Rest\InputParamsResolver-&gt;resolve()
#3 /var/www/myhost.com/public_html/vendor/magento/module-webapi/Controller/Rest.php(216): Magento\Webapi\Controller\Rest-&gt;processApiRequest()
#4 /var/www/myhost.com/public_html/var/generation/Magento/Webapi/Controller/Rest/Interceptor.php(24): Magento\Webapi\Controller\Rest-&gt;dispatch(Object(Magento\Framework\App\Request\Http))
#5 /var/www/myhost.com/public_html/vendor/magento/framework/App/Http.php(135): Magento\Webapi\Controller\Rest\Interceptor-&gt;dispatch(Object(Magento\Framework\App\Request\Http))
#6 /var/www/myhost.com/public_html/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http-&gt;launch()
#7 /var/www/myhost.com/public_html/index.php(39): Magento\Framework\App\Bootstrap-&gt;run(Object(Magento\Framework\App\Http))
#8 {main}</trace>
</response>

도와주세요

답변:


10

인증 토큰은 매개 변수에 배치되지 않습니다. 대신 헤더에 설정해야합니다. POSTMAN의 예는 다음과 같습니다.

여기에 이미지 설명을 입력하십시오

cURL에서는 다음과 같습니다.

curl -X GET --header "Accept: application/json" --header "Authorization: Bearer XXXXXXXXXX" "http://yoursite.com/rest/V1/products/:sku"

답장을 보내 주셔서 감사합니다, 이미 나는 헤더 또는 URL에서 매개 변수로 그것을 시도와 같은 일부 API를 완벽하게 작동 products당신이했던 것처럼하고 categories있지만, 일부 API를 좋아 위해 V1/customers/me, 나는 오류가 발생했습니다. 터미널에서 컬을 실행하더라도 완벽하게 작동합니다. 파이어 폭스에는 우편 배달부와 http 요청자를 사용합니다.
Jsparo30

테스트 사이트에 문제가 없습니다. "베어러"와 토큰 사이에 공백이 있습니까? 그리고 토큰이 만료
PY Yick

HHH, 농담은 무엇입니까 !! 이 공백은 없었고에서 잘 근무 products하고 categories내가 언급 한 바와 같이,하지만 그것을 제거 할 때 customers/me가공 한 고급. 답변을 편집하고 제거 공간의 일부를 추가하여 실제 답변을 제공하십시오. 감사.
Jsparo30

실제로 토큰이 만료 될 가능성이 높습니다. 이전 토큰을 사용하여 API에 액세스하면 질문에 언급 한 것과 동일한 오류가 표시됩니다. 토큰을 갱신하면 문제가 해결됩니다.
PY Yick

Jsparo30 @ 당신은 내가 또한 같은 문제에 직면하고있는 솔루션을 발견했다
Janarthanan Ramu는
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.