Sha256: eac7ffd778ef2804b40d028a61016168ce613838be877e9be75c64ad0df44df8

Contents?: true

Size: 955 Bytes

Versions: 8

Compression:

Stored size: 955 Bytes

Contents

# frozen_string_literal: true

require 'active_support/concern'

module Devise
  module JWT
    module RevocationStrategies
      # This strategy must be included in an ActiveRecord model, and requires
      # that it has a `jti` column.
      #
      # In order to tell whether a token is revoked, it just checks whether
      # `jti` is in the table. On revocation, creates a new record with it.
      module Denylist
        extend ActiveSupport::Concern

        included do
          # @see Warden::JWTAuth::Interfaces::RevocationStrategy#jwt_revoked?
          def self.jwt_revoked?(payload, _user)
            exists?(jti: payload['jti'])
          end

          # @see Warden::JWTAuth::Interfaces::RevocationStrategy#revoke_jwt
          def self.revoke_jwt(payload, _user)
            find_or_create_by!(jti: payload['jti'],
                               exp: Time.at(payload['exp'].to_i))
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
devise-jwt-0.12.1 lib/devise/jwt/revocation_strategies/denylist.rb
devise-jwt-0.12.0 lib/devise/jwt/revocation_strategies/denylist.rb
devise-jwt-0.11.0 lib/devise/jwt/revocation_strategies/denylist.rb
devise-jwt-0.10.0 lib/devise/jwt/revocation_strategies/denylist.rb
devise-jwt-0.9.0 lib/devise/jwt/revocation_strategies/denylist.rb
devise-jwt-0.8.1 lib/devise/jwt/revocation_strategies/denylist.rb
devise-jwt-0.8.0 lib/devise/jwt/revocation_strategies/denylist.rb
devise-jwt-0.7.0 lib/devise/jwt/revocation_strategies/denylist.rb