2016-06-16 4 views
1

私はノックの宝石を使ってjwt認証を実装しています。テストでは、ユーザーの資格情報を正しいURLに送信すると、期待どおりにjwtが返されますが、本番では、資格情報の送信時に同じコードが400応答を返します。私は、送信されたものと本番のdbマッチでユーザーの資格情報をチェックしました。ノックによる認証はテストではあるが生産では機能しない

これらは通過試験である:

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 

?ここで

EDIT は(私はこれが関連ビットだと思う)私は、生産ログで見つけたものです:

2016-06-16T07:28:23.906814+00:00 heroku[router]: at=info method=POST path="/knock/auth_token?auth={%22phone%22=%3E%22my_phone_number%22,%20%22password%22=%3E%22my_password%22}" host=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[router]: at=info method=POST path="/knock/auth_token" host=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]: Started POST "/knock/auth_token" for 110.175.125.233 at 2016-06-16 07:28:56 +0000

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

2016-06-16T07:28:56.415960+00:00 app[web.1]: Completed 400 Bad Request in 1ms (ActiveRecord: 0.0ms) 2016-06-16T07:28:56.418134+00:00 app[web.1]: 2016-06-16T07:28:56.418141+00:00 app[web.1]: ActionController::ParameterMissing (param is missing or the value is empty: auth):

+0

プロダクションログとは何ですか? – devanand

+0

@devanandありがとう、ちょうどそれを入れてください。もっと必要な場合はお知らせください。 –

答えて

0

カール文が正しく要求を形成しません。

私は、Postmanを使用してリクエストを送信し、「生の」タブを使用してリクエストの本文にJSONを入れ、ボディタイプをJSONに設定して、希望の応答を取得することができました。

関連する問題