Devise_auth_token新手在这里。我有一个rails 5 api only app。我试图使用curl向我的api发出请求,但我已成功地成功完成了这项请求,除非我想要登录用户。
curl -XPOST -H 'Content-Type: application/json' -d '{ "session": { "email":"example2@gmail.com", "password": "password"}}' localhost:3000/auth/sign_in
不确定我做错了什么。正如我所说,出于某种原因,创建用户时没有问题。在尝试登录时,我收到此错误
{"errors":["Invalid login credentials. Please try again."]}
非常感谢任何帮助,谢谢。
答案 0 :(得分:0)
curl -v -XPOST -H 'Content-Type: application/json' -d '{ "email":"admin@example.com", "password": "password"}' localhost:3000/auth/sign_in
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 3000 (#0)
> POST /auth/sign_in HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:3000
> Accept: */*
> Content-Type: application/json
> Content-Length: 55
>
* upload completely sent off: 55 out of 55 bytes
< HTTP/1.1 200 OK
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< Content-Type: application/json; charset=utf-8
< access-token: Bm3FaRpSAjT-EtTrj8Ucww
< token-type: Bearer
< client: 6XCiYTxcEITVRZItRKFa8w
< expiry: 1480750998
< uid: admin@example.com
< ETag: W/"be9091473a08ccf2672b9685eb25caa2"
< Cache-Control: max-age=0, private, must-revalidate
< X-Request-Id: 4996fb00-a45c-41e4-b30b-c86bc10b24d5
< X-Runtime: 0.737506
< Transfer-Encoding: chunked
<
* Connection #0 to host localhost left intact
{"data":{"id":1,"email":"admin@example.com","provider":"email","uid":"admin@example.com","name":null,"nickname":null,"image":null}}
使用-v进行卷曲 - 它会给你很多线索。
评论是对的 - 不要在session
内放置登录/密码。
从TL;DR剪断您应该仔细阅读的内容:
身份验证标头包含以下参数:
access-token
,client
,expire
,uid
每个请求所需的身份验证标头将在上一个请求的响应中提供。