我正在尝试将devise-jwt添加到我现有的应用程序中。我现在正在添加API端点,并希望使用已有的相同模型
我在本文后面添加了gem devise-jwt:https://medium.com/@mazik.wyry/rails-5-api-jwt-setup-in-minutes-using-devise-71670fd4ed03
我使用以下命令配置了我的devise.rb文件:
config.jwt do |jwt|
jwt.secret = ENV['DEVISE_JWT_SECRET_KEY']
jwt.dispatch_requests = [
['POST', %r{^/login$}]
]
jwt.revocation_requests = [
['DELETE', %r{^/logout$}]
]
jwt.expiration_time = 1.day.to_i
end我已经为它创建了我的jwt_blacklist.rb和迁移:
class CreateJwtBlacklist < ActiveRecord::Migration[6.0]
def change
create_table :jwt_blacklist do |t|
t.string :jti, null: false
end
add_index :jwt_blacklist, :jti
end
end
class JWTBlacklist < ApplicationRecord
include Devise::JWT::RevocationStrategies::Blacklist
self.table_name = 'jwt_blacklist'
end当我尝试将这些行添加到我的user.rb中时
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, :confirmable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable, omniauth_providers: [:facebook],
:jwt_authenticatable,
jwt_revocation_strategy: JWTBlacklist当我尝试启动我的服务器时,我得到了:
/Users/fmaymone/.rvm/gems/ruby-2.6.3/gems/activesupport-
6.0.0/lib/active_support/dependencies.rb:511:in `load': /booksculp/app/models/user.rb:6:
syntax error, unexpected ',', expecting => (SyntaxError)
:jwt_authenticatable ,有人知道我做错了什么吗?
谢谢
发布于 2019-11-14 09:51:16
将您的User模型更改为以下内容:
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, :confirmable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable,
:jwt_authenticatable, jwt_revocation_strategy: JWTBlacklist, omniauth_providers: [:facebook]https://stackoverflow.com/questions/58525004
复制相似问题