简体   繁体   English

除了从Loopback Restful API登录外,无法获取或发布任何内容

[英]Cannot get or post anything besides login from loopback restful api

I have played around with loopback and I think it's interesting, however it seems to be very restricted, since you can't do anything besides trying to log in in the explorer environment. 我玩过环回,我认为这很有趣,但是它似乎非常受限制,因为除了尝试登录explorer环境外,您无法执行任何其他操作。

The guides and docs was very good at getting the server up and running and I was able to create a user and login, but when trying to get users it throws this error: 指南和文档非常擅长于启动和运行服务器,并且我能够创建用户并登录,但是在尝试get用户时会引发以下错误:

http://localhost:3000/api/users

"error": {
"name": "Error",
"status": 401,
"message": "Authorization Required",
"statusCode": 401,
"stack": "Error: Authorization Required"

I see that you can set some authentication token but I have trouble figuring out how to get that (besides shouldn't it be stored in a session or so when logging in?) 我看到您可以设置一些身份验证令牌,但是我很难弄清楚如何获得该令牌(除了登录时不应该将其存储在会话中?)

The following worked very well, but that's only on the server 以下代码运行良好,但这仅在服务器上

loopback session no method create? 回送会话没有方法创建?

Worth noting is that I have given allow access "acl" for the user so that should not be the problem. 值得注意的是,我已经为用户提供了允许访问权限“ acl”,所以这应该不是问题。

So question is, how do I get some access? 问题是,如何获得访问权限?

I see that you can set some authentication token but I have trouble figuring out how to get that (besides shouldn't it be stored in a session or so when logging in?) 我看到您可以设置一些身份验证令牌,但是我很难弄清楚如何获得该令牌(除了登录时不应该将其存储在会话中?)

See this example I created on authentication and authorization: https://github.com/strongloop/loopback-example-access-control 请参阅我在身份验证和授权上创建的以下示例: https : //github.com/strongloop/loopback-example-access-control

I see that you can set some authentication token but I have trouble figuring out how to get that (besides shouldn't it be stored in a session or so when logging in?) 我看到您可以设置一些身份验证令牌,但是我很难弄清楚如何获得该令牌(除了登录时不应该将其存储在会话中?)

The session mechanism is up to you to implement as LoopBack is not opinionated here. 会话机制由您决定,因为LoopBack在这里没有讨论。 Any session handling library that works with Express will work in LoopBack. 任何与Express一起使用的会话处理库都可以在LoopBack中使用。

您可以通过调用app.enableAuth() 在应用程序中启用身份验证,这意味着您需要在代码中查找该位置,然后将其删除。

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

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