Class: Songkick::OAuth2::Provider::Exchange
- Inherits:
-
Object
- Object
- Songkick::OAuth2::Provider::Exchange
- Defined in:
- lib/songkick/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, transport_error = nil) ⇒ 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, transport_error = nil) ⇒ Exchange
Returns a new instance of Exchange.
19 20 21 22 23 24 25 26 27 |
# File 'lib/songkick/oauth2/provider/exchange.rb', line 19 def initialize(resource_owner, params, transport_error = nil) @params = params @scope = params[SCOPE] @grant_type = @params[GRANT_TYPE] @transport_error = transport_error validate! end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/songkick/oauth2/provider/exchange.rb', line 6 def client @client end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
6 7 8 |
# File 'lib/songkick/oauth2/provider/exchange.rb', line 6 def error @error end |
#error_description ⇒ Object (readonly)
Returns the value of attribute error_description.
6 7 8 |
# File 'lib/songkick/oauth2/provider/exchange.rb', line 6 def error_description @error_description end |
Instance Method Details
#owner ⇒ Object
29 30 31 |
# File 'lib/songkick/oauth2/provider/exchange.rb', line 29 def owner @authorization && @authorization.owner end |
#redirect? ⇒ Boolean
33 34 35 |
# File 'lib/songkick/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 49 50 51 |
# File 'lib/songkick/oauth2/provider/exchange.rb', line 37 def response_body return jsonize(ERROR, ERROR_DESCRIPTION) unless valid? response = {} [ACCESS_TOKEN, REFRESH_TOKEN, SCOPE].each do |key| value = @authorization.__send__(key) response[key] = value if value end if expiry = @authorization.expires_in response[EXPIRES_IN] = expiry end JSON.unparse(response) end |
#response_headers ⇒ Object
53 54 55 |
# File 'lib/songkick/oauth2/provider/exchange.rb', line 53 def response_headers RESPONSE_HEADERS end |
#response_status ⇒ Object
57 58 59 |
# File 'lib/songkick/oauth2/provider/exchange.rb', line 57 def response_status valid? ? 200 : 400 end |
#scopes ⇒ Object
61 62 63 64 |
# File 'lib/songkick/oauth2/provider/exchange.rb', line 61 def scopes scopes = @scope ? @scope.split(/\s+/).delete_if { |s| s.empty? } : [] Set.new(scopes) end |
#update_authorization ⇒ Object
66 67 68 69 70 |
# File 'lib/songkick/oauth2/provider/exchange.rb', line 66 def return if not valid? or @already_updated @authorization.exchange! @already_updated = true end |
#valid? ⇒ Boolean
72 73 74 |
# File 'lib/songkick/oauth2/provider/exchange.rb', line 72 def valid? @error.nil? end |