【发布时间】:2018-02-07 12:19:52
【问题描述】:
我正在尝试为 Magento REST API 创建一个 node.js 客户端。 我使用在自己的 centOS 服务器上运行的社区版。
我使用api的步骤:
- 在 Magento 管理面板中创建具有管理员角色的用户
- 创建新集成
- 激活集成(在此之后,我收到 ConsumerKey、ConsumerSecret、AccessToken、SecretToken)
问题是:当我尝试对我得到的任何端点发出 get 请求时:
{
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 类?
任何帮助将不胜感激!
【问题讨论】:
标签: php node.js rest magento magento2