简体   繁体   English

Rails 5-命名空间路由时,敲击JWT不起作用

[英]Rails 5 - knock for JWT not working when route namespaced

I am using Knock for JWT authentication for Rails 5 API. 我正在使用Knock进行Rails 5 API的JWT身份验证。

I have this Routes file: 我有此路由文件:

Rails.application.routes.draw do
    namespace :api, constraints: { subdomain: 'api' }, path: '/' do
        namespace :v1 do
            post 'user_token' => 'user_token#create'
        end
    end
end

With this, I expect to be able to make a POST request to create new token like this: 这样,我希望能够发出POST请求以创建新令牌,如下所示:

POST http://api.domain.com/v1/user_token POST http://api.domain.com/v1/user_token

but this request gives me the following error: 但是此请求给我以下错误:

NameError: uninitialized constant API::V1::User NameError:未初始化的常量API :: V1 :: User

What I can understand is that Knock is trying to access the model User on the same namespace where the controller ( user_token_controller ) is. 我能理解的是,Knock试图在与控制器( user_token_controller )相同的名称空间上访问模型User But my model are not namespaced: 但是我的模型没有命名空间:

class User < ApplicationRecord
  has_secure_password
  #...
end

My user_token_controller.rb 我的user_token_controller.rb

module API
    module V1
        class UserTokenController < Knock::AuthTokenController
        end
    end
end

What I dong wrong? 我错了什么?

It's a bug already fixed but not yet published. 这是一个已修复但尚未发布的错误。

The temporary solution was using the gem from github code like: 临时解决方案是使用来自github代码的gem:

gem 'knock', github: 'psantos10/knock', branch: 'master' gem'knock',github:'psantos10 / knock',分支:'master'

https://github.com/nsarno/knock/issues/120 https://github.com/nsarno/knock/issues/120

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM