ruby-jwt icon indicating copy to clipboard operation
ruby-jwt copied to clipboard

Getting "no verification key available" when sending an authorization token to a rails API

Open brlafreniere opened this issue 6 years ago • 4 comments

I'm testing my Devise-JWT setup like this:

curl -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIwZWNjMmIzNi04ZmZiLTQ2Y2QtYTZkNi1iZGRjZmU4YTQxNmMiLCJzdWIiOiIxIiwic2NwIjoidXNlciIsImF1ZCI6bnVsbCwiaWF0IjoxNjA1ODQ2NjczLCJleHAiOjE2MDU4NzU0NzN9.ZyqvylXeLZbrRM2V2s5qsyHxiGgElng58HwQ8qjOHCU" http://localhost:3001/quiz_sentences.json
{"error":"No verification key available"}

I can receive an Authorization token:

blaine@devbox:~/langsite/backend [master] $ curl -D - -X POST -d "user[email][email protected]&user[password]=blaine" http://localhost:3001/users/sign_in.json
HTTP/1.1 201 Created
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
[ irrelevant stuff ]
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIwZWNjMmIzNi04ZmZiLTQ2Y2QtYTZkNi1iZGRjZmU4YTQxNmMiLCJzdWIiOiIxIiwic2NwIjoidXNlciIsImF1ZCI6bnVsbCwiaWF0IjoxNjA1ODQ4MDQ2LCJleHAiOjE2MDU4NzY4NDZ9.66Hg_NG3E79-ybC4rJK_XkkSxpLcWHWTlOiw96hyvjg

but sending the same token to a protected endpoint gives me that error.

I don't see any resources available on what to do when this error message is received.

It does seem that this message means that the Authorization header is not being read by the Rails app.

I have already added this to my rails config in config/initializers/cors.rb:

Rails.application.config.middleware.insert_before 0, Rack::Cors do
    allow do
        origins '*'
        resource('*',
            headers: :any,
            expose: ["Authorization"],
            methods: :any
        )
    end
end

My user model:

class User < ApplicationRecord
    include Devise::JWT::RevocationStrategies::JTIMatcher
    # Include default devise modules. Others available are:
    # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
    devise :database_authenticatable, :registerable, :recoverable,
    :rememberable, :validatable, :jwt_authenticatable, jwt_revocation_strategy: self
end

My ApplicationController:

class ApplicationController < ActionController::Base
    protect_from_forgery with: :exception
    before_action :authenticate_user!
end

My JWT config in config/initializers/devise.rb:

    config.jwt do |jwt|
        jwt.secret = Rails.application.credentials.secret_key_jwt
        jwt.dispatch_requests = [
            ['POST', %r{^/users/sign_in$}],
            ['GET', %r{^/$}]
        ]
        jwt.request_formats = { user: [:json] }
        jwt.expiration_time = 8.hours.to_i
    end

Pretty much baffled at what the issue might be. Any help appreciated, thanks.

brlafreniere avatar Nov 20 '20 05:11 brlafreniere

I got this error by using warden-jwt_auth. 0.7.0 broke, but downgrading to 0.6.0 works. if anyone comes across this :) might help

kg-currenxie avatar Oct 05 '22 14:10 kg-currenxie

Im going to close this one.

I have a feeling this is more related to devise-jwt or warden-jwt_auth.

For example: https://github.com/waiting-for-dev/devise-jwt/pull/250

anakinj avatar Oct 05 '22 17:10 anakinj

devise-jwt 0.10.0 fixed this issue for me (up from 0.9.0). warden-jwt_auth 0.7.0 is a dependency of of devise-jwt 0.10.0, but works in that version (not in 0.9.0). Also downgrading warden-jwt_auth to 0.6.0 with devise-jwt 0.9.0 works too as @kg-currenxie pointed out.

hunterpollpeter avatar Oct 05 '22 22:10 hunterpollpeter

@hunterpollpeter Thanks that solved it

Bishoy-Samwel avatar Oct 07 '22 21:10 Bishoy-Samwel