Class: Doorkeeper::OAuth::ErrorResponse

Inherits:
Object
  • Object
show all
Includes:
Authorization::URIBuilder, Helpers
Defined in:
lib/doorkeeper/oauth/error_response.rb

Direct Known Subclasses

ForbiddenTokenResponse, InvalidTokenResponse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Authorization::URIBuilder

#build_query, #uri_with_fragment, #uri_with_query

Constructor Details

#initialize(attributes = {}) ⇒ ErrorResponse

Returns a new instance of ErrorResponse.


14
15
16
17
18
# File 'lib/doorkeeper/oauth/error_response.rb', line 14

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

Class Method Details

.from_request(request, attributes = {}) ⇒ Object


7
8
9
10
# File 'lib/doorkeeper/oauth/error_response.rb', line 7

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

Instance Method Details

#authenticate_infoObject


45
46
47
# File 'lib/doorkeeper/oauth/error_response.rb', line 45

def authenticate_info
  %(Bearer realm="#{realm}", error="#{name}", error_description="#{description}")
end

#bodyObject


20
21
22
23
24
25
26
# File 'lib/doorkeeper/oauth/error_response.rb', line 20

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

#headersObject


49
50
51
52
53
54
# File 'lib/doorkeeper/oauth/error_response.rb', line 49

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

#redirect_uriObject


37
38
39
40
41
42
43
# File 'lib/doorkeeper/oauth/error_response.rb', line 37

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

#redirectable?Boolean

Returns:

  • (Boolean)

32
33
34
35
# File 'lib/doorkeeper/oauth/error_response.rb', line 32

def redirectable?
  name != :invalid_redirect_uri && name != :invalid_client &&
    !URIChecker.native_uri?(@redirect_uri)
end

#statusObject


28
29
30
# File 'lib/doorkeeper/oauth/error_response.rb', line 28

def status
  :unauthorized
end