使用用户模型时,不断在回送中出现401错误 [英] Constantly getting 401 errors in loopback while using User Model
问题描述
我是回传的新手,我无法正确扩展User Base模型.虽然在资源管理器中它显示它已扩展,但是所有API都给出401错误.前任.在正常情况下,我会得到/users的电话.
I am new to loopback and I am not able to extend User Base model properly. Though in explorer it shows that it is extended but all API's give a 401 error. ex. In normal get call for /users I get..
{
"error": {
"name": "Error",
"status": 401,
"message": "Authorization Required",
"statusCode": 401,
"code": "AUTHORIZATION_REQUIRED",
"stack": "Error: Authorization Required"
}
}
我浏览了所有链接和问题,但没有一个对我有用.我已经在用户配置扩展模型的Model-config中正确地设置了public:true并编写了ACL等,但是它们都不起作用.我也对git提出了关于Strongloop的问题: https://github.com/strongloop/loopback/Issues 1809 .任何线索都将很棒.谢谢.
I went thru all the links and questions but none of they are working for me. I have properly put public:true in model-config for User Model extended model and written acls etc. but none of them works. I have also raised an issue on git for strongloop: https://github.com/strongloop/loopback/issues/1809 . Any leads would be awesome. Thanks.
User.json如下:
User.json is as below:
{
"name": "user",
"plural": "users",
"base": "User",
"idInjection": true,
"options": {
"validateUpsert": true
},
"mongodb": {
"collection": "User"
},
"properties": {
"name": {
"type": "string",
"required": true
},
"email": {
"type": "string",
"required": true
},
"password": {
"type": "string",
"required": true
},
"phone": {
"type": "string"
}
},
"validations": [],
"relations": {
"question": {
"type": "hasMany",
"model": "question",
"foreignKey": ""
}
},
"acls": [
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
},
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "admin",
"permission": "ALLOW"
},
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW"
},
{
"accessType": "*",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
}
],
"methods": {}
}
推荐答案
一些注意事项值得考虑:
Some notes meriting consideration though:
1)您正在定义电子邮件,密码,..属性,尽管在父用户模型中已经完全以相同的方式定义了它们;请参阅: https://github.com/strongloop/loopback/blob/master/common/models/user.json ;
1)You are defining email, password,.. properties, although they are already defined exactly the same way in the parent User model; please see: https://github.com/strongloop/loopback/blob/master/common/models/user.json;
2)对于ACL,您缺少访问类型,它们不正确,但是它们不会破坏任何内容...有关ACL的更多信息,请参见:
2)For ACLs you are missing accesstypes, they are not right, but they do not break anything...For more info about ACL please see: https://docs.strongloop.com/display/public/LB/Define+access+controls
3)另外,在登录时,请确保使用已创建的用户(一个POST
请求),并且该用户已经在数据库中.
3)Also when you login please make sure to use user that you have created(a POST
request) and it is in database already.
谢谢!
这篇关于使用用户模型时,不断在回送中出现401错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!