Sha256: cf6c04c60cba47036f5c0d21ba6c0982707d9288d9963ec49a30ff7166a190a1

Contents?: true

Size: 1.19 KB

Versions: 25

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module Doorkeeper
  module OAuth
    class InvalidTokenResponse < ErrorResponse
      attr_reader :reason

      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 initialize(attributes = {})
        super(attributes.merge(name: :invalid_token, state: :unauthorized))
        @reason = attributes[:reason] || :unknown
      end

      def status
        :unauthorized
      end

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

      protected

      def exception_class
        errors_mapping.fetch(reason)
      end

      private

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

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
doorkeeper-5.8.0 lib/doorkeeper/oauth/invalid_token_response.rb
doorkeeper-5.7.1 lib/doorkeeper/oauth/invalid_token_response.rb
doorkeeper-5.7.0 lib/doorkeeper/oauth/invalid_token_response.rb
doorkeeper-5.6.9 lib/doorkeeper/oauth/invalid_token_response.rb
doorkeeper-5.6.8 lib/doorkeeper/oauth/invalid_token_response.rb
doorkeeper-5.6.7 lib/doorkeeper/oauth/invalid_token_response.rb
doorkeeper-5.6.6 lib/doorkeeper/oauth/invalid_token_response.rb
doorkeeper-5.6.5 lib/doorkeeper/oauth/invalid_token_response.rb
doorkeeper-5.6.4 lib/doorkeeper/oauth/invalid_token_response.rb
doorkeeper-5.6.3 lib/doorkeeper/oauth/invalid_token_response.rb
doorkeeper-5.6.2 lib/doorkeeper/oauth/invalid_token_response.rb
doorkeeper-5.6.1 lib/doorkeeper/oauth/invalid_token_response.rb
doorkeeper-5.6.0 lib/doorkeeper/oauth/invalid_token_response.rb
doorkeeper-5.6.0.rc2 lib/doorkeeper/oauth/invalid_token_response.rb
doorkeeper-5.6.0.rc1 lib/doorkeeper/oauth/invalid_token_response.rb
doorkeeper-5.5.4 lib/doorkeeper/oauth/invalid_token_response.rb
doorkeeper-5.5.3 lib/doorkeeper/oauth/invalid_token_response.rb
doorkeeper-5.5.2 lib/doorkeeper/oauth/invalid_token_response.rb
doorkeeper-5.5.1 lib/doorkeeper/oauth/invalid_token_response.rb
doorkeeper-5.5.0 lib/doorkeeper/oauth/invalid_token_response.rb