Sha256: 2cdb99f30024c98fc0c02d6293d746e6f3fd0e7c5978d0ab7321be2996bee95d

Contents?: true

Size: 1.12 KB

Versions: 7

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

module Doorkeeper
  module OAuth
    class InvalidRequestResponse < ErrorResponse
      attr_reader :reason

      def self.from_request(request, attributes = {})
        new(
          attributes.merge(
            state: request.try(:state),
            redirect_uri: request.try(:redirect_uri),
            missing_param: request.try(:missing_param),
            reason: request.try(:invalid_request_reason),
          ),
        )
      end

      def initialize(attributes = {})
        super(attributes.merge(name: :invalid_request))
        @missing_param = attributes[:missing_param]
        @reason = @missing_param.nil? ? attributes[:reason] : :missing_param
      end

      def status
        :bad_request
      end

      def description
        I18n.translate(
          reason,
          scope: %i[doorkeeper errors messages invalid_request],
          default: :unknown,
          value: @missing_param,
        )
      end

      def exception_class
        Doorkeeper::Errors::InvalidRequest
      end

      def redirectable?
        super && @missing_param != :client_id
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
doorkeeper-5.8.1 lib/doorkeeper/oauth/invalid_request_response.rb
doorkeeper-5.8.0 lib/doorkeeper/oauth/invalid_request_response.rb
doorkeeper-5.7.1 lib/doorkeeper/oauth/invalid_request_response.rb
doorkeeper-5.7.0 lib/doorkeeper/oauth/invalid_request_response.rb
doorkeeper-5.6.9 lib/doorkeeper/oauth/invalid_request_response.rb
doorkeeper-5.6.8 lib/doorkeeper/oauth/invalid_request_response.rb
doorkeeper-5.6.7 lib/doorkeeper/oauth/invalid_request_response.rb