简体   繁体   中英

ROR: devise-jwt : how to call jwt_revoked? function?

I am using devise and devise-jwt for my ror api. I would like to let know the user (by api call) if the user bearer token sent is revoked or not.

I made this route:

  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

But it produces me this error: #<NoMethodError: undefined method `jwt_revoked?' for #User:0x0000558992eb9b98>

I am using this jwt_revocation_strategy: JwtBlacklist in my model:

class JwtBlacklist < ApplicationRecord
  include Devise::JWT::RevocationStrategies::Denylist
  self.table_name = 'jwt_blacklists'
end

How to call jwt_revoked? function??

Thanks

jwt_revoked? is part of the Devise::JWT::RevocationStrategies::Denylist module. So you'll need to call JwtBlacklist model

JwtBlacklist.jwt_revoked?(decoded, user)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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