私はRails 5 APIのみのアプリケーションを持ち、JWT認証を行うにはknockを使用しています。RSpecを使用してJWT認証アプリケーションの要求仕様を行う方法
モデルとモデル仕様が完成した後、私は要求仕様を開始します。
しかし、私は正しい方法で要求スペック内の認証を完了するために、どのようには考えている、
マイユーザーコントローラ、
module V1
class UsersController < ApplicationController
before_action :authenticate_user, except: [:create]
end
end
アプリケーションコントローラ、
class ApplicationController < ActionController::API
include Knock::Authenticable
include ActionController::Serialization
end
私の愚かな解決策(残りの要求の前にJWTを取得するトークントークンを呼び出す)
context 'when the request contains an authentication header' do
it 'should return the user info' do
user = create(:user)
post '/user_token', params: {"auth": {"email": user.email, "password": user.password }}
body = response.body
puts body # {"jwt":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE0ODgxMDgxMDYsInN1YiI6MX0.GDBHPzbivclJfwSTswXhDkV0TCFCybJFDrjBnLIfN3Q"}
# use the retrieved JWT for future requests
end
end
アドバイスありがとうございます。