使用 cURL 设计身份验证 [英] Devise Authentication using cURL

查看:39
本文介绍了使用 cURL 设计身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 Devise 从终端使用 cURL 验证我的 Ruby on Rails 应用程序?

How can I authenticate my Ruby on Rails Application using cURL from terminal using Devise?

我正在尝试:

curl --user email:password http://domain.bla/api/auth/sign_in

并且正在回应:

您要找的页面不存在.

推荐答案

这对我有用:

curl -XPOST -v -H 'Content-Type: application/json' http://domain/api/v1/auth/sign_in -d '{"email": "email@domain.com", "password": "password" }

所以我得到了回复(如下所示,只是重要的部分):

So I get back the response (something like below, only important part) :

< access-token: lW1c60hYkRwAinzUqgLfsQ
< token-type: Bearer
< client: W_xCQuggzNOVeCnNZbjKFw
< expiry: 1426610121
< uid: email@domain.com

然后我可以验证令牌,使用之前从上述请求中获得的客户端和令牌,我这样做:

Then I can validate the token, using the client and token previously obtained from the above request, I do it like this :

curl -XGET -v -H 'Content-Type: application/json' -H 'access-token: lW1c60hYkRwAinzUqgLfsQ' -H 'client: W_xCQuggzNOVeCnNZbjKFw' -H "uid: email@domain.com" http://domain/api/v1/auth/validate_token

结果:

{"success":true,"data":{"id":3,"provider":"email","uid":"email@domain.com","firstname":null,"lastname":null,"email":"email@domain.com"}}

这篇关于使用 cURL 设计身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆