环回无法使用PUT请求更新用户/客户
我有一个扩展了内置用户模型的客户模型。但即使提供了正确的access_token,PUT请求更新客户也不起作用。环回无法使用PUT请求更新用户/客户
我以登录终端用户的身份登录并获得了access_token。 的PUT请求更新客户属性:
PUT http://localhost:3000/api/customers/59cb873ab21a902ab0afece1
按我的理解,业主应该可以更新自己的纪录,但它不断抛出以下错误:
{
"error": {
"statusCode": 401,
"name": "Error",
"message": "Authorization Required"
}
}
此外,当我尝试删除使用相同的access_token它工作正常。
DELETE http://localhost:3000/api/customers/59cb873ab21a902ab0afece1
的customer.json文件看起来象下面这样:
{
"name": "customer",
"plural": "customers",
"base": "User",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"realm": null,
"emailVerified": null,
"name": {
"type": "string"
},
"username": {
"type": "string"
},
"cellnumber": {
"type": "string"
},
"status": {
"type": "string"
}
},
"validations": [],
"relations": {
"accessTokens": {
"type": "hasMany",
"model": "accessToken",
"foreignKey": "userId"
}
},
"acls": [
],
"methods": {},
"replaceOnPUT": false
}
我要去哪里错了?我如何解决这个问题?
感谢
您可以尝试提供用户,ACL像下面的例子中,
"acls": [
{
"accessType": "EXECUTE",
"principalType": "ROLE",
"principalId": "$authenticated",
"permission": "ALLOW"
}, {
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
}
]
希望这会工作。
用户模型的默认ACL需要验证,除了POST请求以外的每个请求 - 所以这不是问题。
要在此模型上发出GET,PUT/PATCH或DELETE请求,您需要在请求中登录并使用令牌。
例子,你的情况:
- 发布一个新的客户,如:
{ "username": "stack_user", "email": "[email protected]", "password":"*" }
; 在POST http://localhost:3000/api/customers/
- 使用电子邮件和密码登录:
{ "email": "[email protected]", "password":"*" }
; 在POST http://localhost:3000/api/customers/login
=>你会得到这样的回应:
{
"id": "jazSRZYbjJai3JeCYpb6u4nYsRGWbaQk5SK3nQPkMoNeUdrAYK3kYwaXECrfj6Vk",
"ttl": 1209600,
"created": "2017-09-29T11:44:16.111Z",
"userId": "59cb873ab21a902ab0afece1"
}
其中ID是的access_token。
- 在
PUT http://localhost:3000/api/customers/59cb873ab21a902ab0afece1?access_token=jazSRZYbjJai3JeCYpb6u4nYsRGWbaQk5SK3nQPkMoNeUdrAYK3kYwaXECrfj6Vk
使用它,它应该工作。
如果没有,你可以尝试删除该行:
"replaceOnPUT": false
,然后再试一次?
嗨F3LIX79,我遵循相同的,但它不工作。删除replaceOnPut也无济于事。当我们扩展默认的用户模型时,这似乎是一个问题。 –
您是否设法通过在浏览器页面右上角设置访问令牌来使其在Swagger的“API Explorer”中工作? – F3L1X79
不能。它在API swagger或Postman中无法使用访问令牌。 –
不,它不起作用。当默认用户模型已经有一个时,添加更多ACL的用途是什么。问题是默认ACL不起作用。 –