Sha256: 3f411aa3adfc919e53e2f121b580dcc389e907ecdb036cbd54feaa3002a4e22c

Contents?: true

Size: 835 Bytes

Versions: 2

Compression:

Stored size: 835 Bytes

Contents

module Doorkeeper
  module OAuth
    class InvalidTokenResponse < ErrorResponse
      attr_reader :reason

      def self.from_access_token(access_token, attributes = {})
        reason = case
                 when access_token.try(:revoked?)
                   :revoked
                 when access_token.try(:expired?)
                   :expired
                 else
                   :unknown
                 end

        new(attributes.merge(reason: reason))
      end

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

      def description
        scope = { scope: [:doorkeeper, :errors, :messages, :invalid_token] }
        @description ||= I18n.translate @reason, scope
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
doorkeeper-4.2.6 lib/doorkeeper/oauth/invalid_token_response.rb
doorkeeper-4.2.5 lib/doorkeeper/oauth/invalid_token_response.rb