Module: OAuth2::Provider::Rack::Responses
- Included in:
- ResourceRequest
- Defined in:
- lib/oauth2/provider/rack/responses.rb
Class Method Summary collapse
- .json_error(error, options = {}) ⇒ Object
- .only_supported(supported) ⇒ Object
- .redirect_with_code(code, uri) ⇒ Object
- .redirect_with_error(error, uri) ⇒ Object
- .unauthorized(error = nil) ⇒ Object
Instance Method Summary collapse
- #authentication_required!(reason = nil) ⇒ Object
- #insufficient_scope! ⇒ Object
- #invalid_request!(description) ⇒ Object
Class Method Details
.json_error(error, options = {}) ⇒ Object
14 15 16 17 |
# File 'lib/oauth2/provider/rack/responses.rb', line 14 def self.json_error(error, = {}) description = %{, "error_description": "#{[:description]}"} if [:description] [[:status] || 400, {'Content-Type' => 'application/json'}, [%{{"error": "#{error}"#{description}}}]] end |
.only_supported(supported) ⇒ Object
10 11 12 |
# File 'lib/oauth2/provider/rack/responses.rb', line 10 def self.only_supported(supported) [405, {'Allow' => supported}, ["Only #{supported} requests allowed"]] end |
.redirect_with_code(code, uri) ⇒ Object
23 24 25 |
# File 'lib/oauth2/provider/rack/responses.rb', line 23 def self.redirect_with_code(code, uri) [302, {'Location' => append_to_uri(uri, :code => code)}, []] end |
.redirect_with_error(error, uri) ⇒ Object
19 20 21 |
# File 'lib/oauth2/provider/rack/responses.rb', line 19 def self.redirect_with_error(error, uri) [302, {'Location' => append_to_uri(uri, :error => error)}, []] end |
.unauthorized(error = nil) ⇒ Object
4 5 6 7 8 |
# File 'lib/oauth2/provider/rack/responses.rb', line 4 def self.(error = nil) challenge = "OAuth2" challenge << %{ error="#{error}"} if error [401, {'Content-Type' => 'text/plain', 'Content-Length' => '0', 'WWW-Authenticate' => challenge}, []] end |
Instance Method Details
#authentication_required!(reason = nil) ⇒ Object
35 36 37 38 |
# File 'lib/oauth2/provider/rack/responses.rb', line 35 def authentication_required!(reason = nil) env['warden'] && env['warden'].custom_failure! throw_response OAuth2::Provider::Rack::Responses.(reason) end |
#insufficient_scope! ⇒ Object
27 28 29 |
# File 'lib/oauth2/provider/rack/responses.rb', line 27 def insufficient_scope! throw_response OAuth2::Provider::Rack::Responses.json_error('insufficient_scope', :status => 403) end |
#invalid_request!(description) ⇒ Object
31 32 33 |
# File 'lib/oauth2/provider/rack/responses.rb', line 31 def invalid_request!(description) throw_response OAuth2::Provider::Rack::Responses.json_error('invalid_request', :description => description, :status => 401) end |