class Doorkeeper::OAuth::ErrorResponse
Constants
- NON_REDIRECTABLE_STATES
Public Class Methods
Source
# File lib/doorkeeper/oauth/error_response.rb, line 10 def self.from_request(request, attributes = {}) new( attributes.merge( name: error_name_for(request.error), exception_class: exception_class_for(request.error), translate_options: request.error.try(:translate_options), state: request.try(:state), redirect_uri: request.try(:redirect_uri), ), ) end
Source
# File lib/doorkeeper/oauth/error_response.rb, line 36 def initialize(attributes = {}) @error = OAuth::Error.new(*attributes.values_at(:name, :state, :translate_options)) @exception_class = attributes[:exception_class] @redirect_uri = attributes[:redirect_uri] @response_on_fragment = attributes[:response_on_fragment] end
Private Class Methods
Source
# File lib/doorkeeper/oauth/error_response.rb, line 22 def self.error_name_for(error) error.respond_to?(:name_for_response) ? error.name_for_response : error end
Source
# File lib/doorkeeper/oauth/error_response.rb, line 26 def self.exception_class_for(error) return error if error.respond_to?(:name_for_response) "Doorkeeper::Errors::#{error.to_s.classify}".safe_constantize end
Public Instance Methods
Source
# File lib/doorkeeper/oauth/error_response.rb, line 43 def body { error: name, error_description: description, state: state, }.reject { |_, v| v.blank? } end
Source
# File lib/doorkeeper/oauth/error_response.rb, line 71 def headers { "Cache-Control" => "no-store, no-cache", "Content-Type" => "application/json; charset=utf-8", "WWW-Authenticate" => authenticate_info, } end
Source
# File lib/doorkeeper/oauth/error_response.rb, line 79 def raise_exception! raise exception_class.new(self), description end
Source
# File lib/doorkeeper/oauth/error_response.rb, line 63 def redirect_uri if @response_on_fragment Authorization::URIBuilder.uri_with_fragment(@redirect_uri, body) else Authorization::URIBuilder.uri_with_query(@redirect_uri, body) end end
Source
# File lib/doorkeeper/oauth/error_response.rb, line 59 def redirectable? !NON_REDIRECTABLE_STATES.include?(name) && !URIChecker.oob_uri?(@redirect_uri) end
Source
# File lib/doorkeeper/oauth/error_response.rb, line 51 def status if name == :invalid_client || name == :unauthorized_client :unauthorized else :bad_request end end
Protected Instance Methods
Source
# File lib/doorkeeper/oauth/error_response.rb, line 89 def exception_class return @exception_class if @exception_class raise NotImplementedError, "error response must define #exception_class" end
Source
# File lib/doorkeeper/oauth/error_response.rb, line 85 def realm Doorkeeper.config.realm end
Private Instance Methods
Source
# File lib/doorkeeper/oauth/error_response.rb, line 96 def authenticate_info %(Bearer realm="#{realm}", error="#{name}", error_description="#{description}") end