class Doorkeeper::OAuth::InvalidTokenResponse

def self.from_access_token(access_token, attributes = {})

def self.from_access_token(access_token, attributes = {})
  reason = if access_token&.revoked?
             :revoked
           elsif access_token&.expired?
             :expired
           else
             :unknown
           end
  new(attributes.merge(reason: reason))
end

def description

def description
  @description ||=
    I18n.translate(
      @reason,
      scope: %i[doorkeeper errors messages invalid_token],
    )
end

def errors_mapping

def errors_mapping
  {
    expired: Doorkeeper::Errors::TokenExpired,
    revoked: Doorkeeper::Errors::TokenRevoked,
    unknown: Doorkeeper::Errors::TokenUnknown,
  }
end

def exception_class

def exception_class
  errors_mapping.fetch(reason)
end

def initialize(attributes = {})

def initialize(attributes = {})
  super(attributes.merge(name: :invalid_token, state: :unauthorized))
  @reason = attributes[:reason] || :unknown
end

def status

def status
  :unauthorized
end