【问题标题】:Devise Authentication using cURL使用 cURL 设计身份验证
【发布时间】:2015-05-04 15:46:05
【问题描述】:

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

我正在尝试:

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

并且正在响应:

您要查找的页面不存在。

【问题讨论】:

    标签: ruby-on-rails api curl devise


    【解决方案1】:

    我发现登录步骤需要包含在user 字典中,即:

    curl -X POST -v -H 'Content-Type: application/json' \ 
      http://somehost.com/users/sign_in -d \ 
      '{"user" : {"email": "some_user@nowhereville.org", "password": "OpenSecret" }}'
    

    这是设计 3.5.4。

    【讨论】:

      【解决方案2】:

      这对我有用:

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

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

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

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

      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"}}
      

      【讨论】:

      • 现在可以给我一个put方法的例子吗?
      • 嘿,抱歉,这对我不起作用。我总是有 401 状态码,为什么?
      猜你喜欢
      • 2012-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-15
      • 1970-01-01
      • 2010-12-07
      • 2013-08-17
      • 2020-08-28
      相关资源
      最近更新 更多