Class: Doorkeeper::OAuth::ErrorResponse
Constant Summary
collapse
- NON_REDIRECTABLE_STATES =
i[invalid_redirect_uri invalid_client unauthorized_client].freeze
Class Method Summary
collapse
Instance Method Summary
collapse
#description
Constructor Details
#initialize(attributes = {}) ⇒ ErrorResponse
22
23
24
25
26
|
# File 'lib/doorkeeper/oauth/error_response.rb', line 22
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
10
11
12
13
14
15
16
17
18
|
# File 'lib/doorkeeper/oauth/error_response.rb', line 10
def self.from_request(request, attributes = {})
new(
attributes.merge(
name: request.error,
state: request.try(:state),
redirect_uri: request.try(:redirect_uri),
),
)
end
|
Instance Method Details
#body ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/doorkeeper/oauth/error_response.rb', line 28
def body
{
error: name,
error_description: description,
state: state,
}.reject { |_, v| v.blank? }
end
|
56
57
58
59
60
61
62
63
|
# File 'lib/doorkeeper/oauth/error_response.rb', line 56
def
{
"Cache-Control" => "no-store",
"Pragma" => "no-cache",
"Content-Type" => "application/json; charset=utf-8",
"WWW-Authenticate" => authenticate_info,
}
end
|
#raise_exception! ⇒ Object
65
66
67
|
# File 'lib/doorkeeper/oauth/error_response.rb', line 65
def raise_exception!
raise exception_class.new(self), description
end
|
#redirect_uri ⇒ Object
48
49
50
51
52
53
54
|
# File 'lib/doorkeeper/oauth/error_response.rb', line 48
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
|
#redirectable? ⇒ Boolean
44
45
46
|
# File 'lib/doorkeeper/oauth/error_response.rb', line 44
def redirectable?
!NON_REDIRECTABLE_STATES.include?(name) && !URIChecker.oob_uri?(@redirect_uri)
end
|
#status ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/doorkeeper/oauth/error_response.rb', line 36
def status
if name == :invalid_client || name == :unauthorized_client
:unauthorized
else
:bad_request
end
end
|