[英]Magento 2 REST API
我正在尝试为Magento REST API创建一个node.js客户端。 我使用在自己的centOS服务器上运行的社区版。
我使用API的步骤如下:
问题是:当我尝试对任何端点的获取请求时,我得到:
{
Client is not authorized to access this resource: ResourceName
}
请求是:
request({
url: this.url+endpoint,
method: 'GET',
headers:{
'Authorization': 'Bearer '+bearer,
'User-Agent': '...',
'Accept' : 'application/json',
'Content-Type': 'application/json'
}
}, (error, response, body) => {
callback(error,response,body)
})
})
我通过此请求正确获得了承载(我检查了它)令牌:
request({
url: this.url+'integration/admin/token',
method: 'POST',
json:{
username: this.username,
password: this.password
}
}, (error, response, body) => {
callback(body)
})
浏览magento安装过程中,我遇到了授权请求:
public function isAllowed($resource, $privilege = null)
{
return $this->_aclPolicy->isAllowed($this->_aclRoleLocator->getAclRoleId(), $resource, $privilege);
}
如果我变成
return true
我无需身份验证即可访问所有资源,但这不是我想要的
我检查了功能
getAclRoleId()
我发现了这个DefaultRoleLocator.php
namespace Magento\Framework\Authorization\RoleLocator;
class DefaultRoleLocator implements
\Magento\Framework\Authorization\RoleLocatorInterface
{
/**
* Retrieve current role
*
* @return string
*/
public function getAclRoleId()
{
return '';
}
}
我的PHP不太好,我是magento的新手。 甚至oauth身份验证也会失败。
我必须更改此功能? 我必须创建另一个RoleLocator类吗?
任何帮助将非常感激 !
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.