首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >devise-jwt :如何调用jwt_revoked?函数?

devise-jwt :如何调用jwt_revoked?函数?
EN

Stack Overflow用户
提问于 2021-02-17 22:28:29
回答 1查看 184关注 0票数 0

我使用devise和devise-jwt作为我的ror api。我想让用户知道(通过api调用)发送的用户持有者令牌是否被撤销。

我走了这条路:

代码语言:javascript
复制
  def user_token_revoked
    decoder = JWT::Decode.new(
      request.headers['Authorization'].split(' ')[1],
      'GENERATED_TOKEN',
      nil,
      nil
    )
    decoded = decoder.decode_segments
    user = User.find_by_id(decoded[0]['sub']) # get id user from decoded token
    render json: user.jwt_revoked?(decoded), status: :ok
  end

但它产生了这样的错误:#

我在我的模型中使用这个jwt_revocation_strategy: JwtBlacklist:

代码语言:javascript
复制
class JwtBlacklist < ApplicationRecord
  include Devise::JWT::RevocationStrategies::Denylist
  self.table_name = 'jwt_blacklists'
end

如何调用jwt_revoked?函数??

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-17 23:04:09

jwt_revoked?Devise::JWT::RevocationStrategies::Denylist模块的一部分。因此您需要调用JwtBlacklist模型

代码语言:javascript
复制
JwtBlacklist.jwt_revoked?(decoded, user)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66243944

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档