【问题标题】:Authentication with Knock works in testing but not production使用 Knock 进行身份验证适用于测试,但不适用于生产
【发布时间】:2016-06-16 06:10:41
【问题描述】:

我正在使用 Knock gem 来实现 jwt 身份验证。在测试中,当我将用户凭据发送到正确的 url 时,jwt 会按预期返回,但在生产中,当发送凭据时,相同的代码会返回 400 响应。我已经检查了生产数据库中用户的凭据是否与发送的凭据相匹配。

这些是通过的测试:

  test 'get authentication token' do
    post '/knock/auth_token', {auth: {phone: @user.phone, password: 'password'}}
    response = ActiveSupport::JSON.decode @response.body
    assert_match /.*\..*\..*/, response['jwt']
  end

  test 'no authentication on bad credentials' do
    post '/knock/auth_token', {auth: {phone: @user.phone, password: 'invalid'}}
    assert_response :missing
  end

这是得到 400 错误的 curl 命令:

curl -v --data "{\"auth\":{\"phone\":\"my_phone_number\",\"password\":\"my_password\"}}" https://production.server.com/knock/auth_token

这是怎么回事?

编辑 这是我在生产日志中发现的(我认为这是相关位):

2016-06-16T07:28:23.906814+00:00 heroku[路由器]: at=info method=POST path="/knock/auth_token?auth={%22phone%22=%3E%22my_phone_number%22,%20%22password%22=%3E%22my_password%22}" 主机=production.server.com request_id=33e6189c-bccb-432a-af64-78ef890fbb4f fwd="110.175.125.233" dyno=web.1 connect=0ms service=14ms status=500 bytes=1714

2016-06-16T07:28:56.429852+00:00 heroku[路由器]: at=info method=POST path="/knock/auth_token" 主机=production.server.com request_id=86f182b9-c1a9-40c0-abaa-30d488194cb8 fwd="110.175.125.233" dyno=web.1 connect=0ms service=33ms status=400 bytes=224

2016-06-16T07:28:56.406561+00:00 app[web.1]:开始发布 110.175.125.233 的“/knock/auth_token” 2016-06-16 07:28:56 +0000

2016-06-16T07:28:56.415192+00:00 app[web.1]:处理者 Knock::AuthTokenController#create as /

2016-06-16T07:28:56.415960+00:00 app[web.1]:已完成 400 错误请求 在 1 毫秒内(活动记录:0.0 毫秒) 2016-06-16T07:28:56.418134+00:00 应用 [web.1]:2016-06-16T07:28:56.418141+00:00 应用 [web.1]: ActionController::ParameterMissing(参数丢失或值为 空:身份验证):

【问题讨论】:

  • 生产日志怎么说?
  • @devanand 谢谢,把它放进去。如果你需要更多,请告诉我。

标签: ruby-on-rails jwt


【解决方案1】:

curl 语句没有正确形成请求。

我通过使用 Postman 提交请求、使用“原始”选项卡将 JSON 放入请求的正文并将正文类型设置为 JSON 来设法从服务器获得所需的响应。

【讨论】:

    猜你喜欢
    • 2022-11-24
    • 2016-11-11
    • 2014-08-16
    • 2017-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-09
    相关资源
    最近更新 更多