Class: OAuth2::Provider::Exchange
- Inherits:
-
Object
- Object
- OAuth2::Provider::Exchange
- Defined in:
- lib/oauth2/provider/exchange.rb
Constant Summary collapse
- REQUIRED_PARAMS =
[CLIENT_ID, CLIENT_SECRET, GRANT_TYPE]
- VALID_GRANT_TYPES =
[AUTHORIZATION_CODE, PASSWORD, ASSERTION, REFRESH_TOKEN]
- REQUIRED_PASSWORD_PARAMS =
[USERNAME, PASSWORD]
- REQUIRED_ASSERTION_PARAMS =
[ASSERTION_TYPE, ASSERTION]
- RESPONSE_HEADERS =
{ 'Cache-Control' => 'no-store', 'Content-Type' => 'application/json' }
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#error_description ⇒ Object
readonly
Returns the value of attribute error_description.
Instance Method Summary collapse
-
#initialize(resource_owner, params) ⇒ Exchange
constructor
A new instance of Exchange.
- #owner ⇒ Object
- #redirect? ⇒ Boolean
- #response_body ⇒ Object
- #response_headers ⇒ Object
- #response_status ⇒ Object
- #scopes ⇒ Object
- #update_authorization ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(resource_owner, params) ⇒ Exchange
Returns a new instance of Exchange.
18 19 20 21 22 23 |
# File 'lib/oauth2/provider/exchange.rb', line 18 def initialize(resource_owner, params) @params = params @scope = params[SCOPE] @grant_type = @params[GRANT_TYPE] validate! end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
5 6 7 |
# File 'lib/oauth2/provider/exchange.rb', line 5 def client @client end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
5 6 7 |
# File 'lib/oauth2/provider/exchange.rb', line 5 def error @error end |
#error_description ⇒ Object (readonly)
Returns the value of attribute error_description.
5 6 7 |
# File 'lib/oauth2/provider/exchange.rb', line 5 def error_description @error_description end |
Instance Method Details
#owner ⇒ Object
25 26 27 |
# File 'lib/oauth2/provider/exchange.rb', line 25 def owner @authorization && @authorization.owner end |
#redirect? ⇒ Boolean
33 34 35 |
# File 'lib/oauth2/provider/exchange.rb', line 33 def redirect? false end |
#response_body ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/oauth2/provider/exchange.rb', line 37 def response_body return jsonize(ERROR, ERROR_DESCRIPTION) unless valid? response = {} %w[access_token refresh_token scope].each do |key| value = @authorization.__send__(key) response[key] = value if value end JSON.unparse(response) end |
#response_headers ⇒ Object
50 51 52 |
# File 'lib/oauth2/provider/exchange.rb', line 50 def response_headers RESPONSE_HEADERS end |
#response_status ⇒ Object
54 55 56 |
# File 'lib/oauth2/provider/exchange.rb', line 54 def response_status valid? ? 200 : 400 end |
#scopes ⇒ Object
29 30 31 |
# File 'lib/oauth2/provider/exchange.rb', line 29 def scopes @scope ? @scope.split(/\s+/).delete_if { |s| s.empty? } : [] end |
#update_authorization ⇒ Object
58 59 60 61 62 |
# File 'lib/oauth2/provider/exchange.rb', line 58 def return if not valid? or @already_updated @authorization.exchange! @already_updated = true end |
#valid? ⇒ Boolean
64 65 66 |
# File 'lib/oauth2/provider/exchange.rb', line 64 def valid? @error.nil? end |