简体   繁体   English

环回使用REST作为数据源登录用户

[英]Loopback Login a user with REST as datasource

I have a UserModel that has a base model USER and a REST datasource 我有一个UserModel,它有一个基本模型USER和一个REST数据源

"UserModel": { "dataSource": "mock", "public": true } 

Data Source 数据源

"mock": { "name": "mock", "baseURL": "http://localhost:3000/", "connector": "rest" }, 

The UserModel UserModel

{ "name": "UserModel", "base": "User", "idInjection": true, "options": { "validateUpsert": true }, "properties": {}, "validations": [], "relations": {}, "acls": [], "methods": {} } 

The problem when I call /UserModel/login with a post and a body like 当我用一个帖子和一个身体调用/ UserModel / login时的问题

{"username": "test", "password": "123"}

in the mock server I only get a call without even the password to: 在模拟服务器中,我只接到一个呼叫,甚至没有密码:

/UserModels?where%5Busername%5D=test&limit=1&offset=0&skip=0

I want to handle the login through REST and a backend that receives the Username and password check for them and return 200 or 401 我想通过REST和后端处理登录,后端接收用户名和密码检查它们并返回200或401

Try defining the login endpoint in datasources.json using a POST method 尝试使用POST方法在datasources.json定义登录端点

"operations": [{
            "template": {
                "method": "POST",
                "url": "http://localhost:3000/MockedUsers??",
                "headers": {
                    "accepts": "application/json",
                    "content-type": "application/json"
                },
                "query": {
                    "username": "{username}",
                    "password": "{password}"
                },

            }
        }]

Haven't tested it though, let me know if it's helpful. 没有测试过,让我知道它是否有用。 Documentation could be more clear on this topic IMO. 关于IMO这一主题的文件可以更清楚。

Finally got the issue. 终于得到了这个问题。 It was a misunderstanding. 这是一个误解。 Loopback tries to log in on his own so he needs the user model so in his tier it can hash the input password and try to assert the two data. Loopback尝试自己登录,因此他需要用户模型,因此在他的层中,它可以散列输入密码并尝试断言这两个数据。 So it needs to get the user as it did. 所以它需要让用户像它一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM