Sha256: ca2c21c4a81578ba2f4bd771ea03379f32dae533187c3174bdd84dd9d4ba8cb4

Contents?: true

Size: 1.23 KB

Versions: 11

Compression:

Stored size: 1.23 KB

Contents

module Doorkeeper
  module OAuth
    class ErrorResponse
      include Doorkeeper::OAuth::Authorization::URIBuilder

      def self.from_request(request, attributes = {})
        state = request.state if request.respond_to?(:state)
        new(attributes.merge(:name => request.error, :state => state))
      end

      delegate :name, :description, :state, :to => :@error

      def initialize(attributes = {})
        @error = Doorkeeper::OAuth::Error.new(*attributes.values_at(:name, :state))
        @redirect_uri = attributes[:redirect_uri]
        @response_on_fragment = attributes[:response_on_fragment]
      end

      def body
        { :error => name, :error_description => description, :state => state }.reject { |k, v| v.blank? }
      end

      def status
        :unauthorized
      end

      def redirectable?
        (name != :invalid_redirect_uri) && (name != :invalid_client)
      end

      def redirect_uri
        if @response_on_fragment
          uri_with_fragment @redirect_uri, body
        else
          uri_with_query @redirect_uri, body
        end
      end

      def headers
        { 'Cache-Control' => 'no-store', 'Pragma' => 'no-cache', 'Content-Type' => 'application/json; charset=utf-8' }
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
doorkeeper-1.0.0.rc1 lib/doorkeeper/oauth/error_response.rb
doorkeeper-0.7.4 lib/doorkeeper/oauth/error_response.rb
doorkeeper-0.7.3 lib/doorkeeper/oauth/error_response.rb
doorkeeper-0.7.2 lib/doorkeeper/oauth/error_response.rb
doorkeeper-0.7.1 lib/doorkeeper/oauth/error_response.rb
doorkeeper-0.7.0 lib/doorkeeper/oauth/error_response.rb
doorkeeper-0.6.7 lib/doorkeeper/oauth/error_response.rb
doorkeeper-0.6.6 lib/doorkeeper/oauth/error_response.rb
doorkeeper-0.6.5 lib/doorkeeper/oauth/error_response.rb
doorkeeper-0.6.4 lib/doorkeeper/oauth/error_response.rb
doorkeeper-0.6.3 lib/doorkeeper/oauth/error_response.rb