Module: HomeAway::API::Util::OAuth
- Included in:
- Client
- Defined in:
- lib/homeaway/api/util/oauth.rb
Instance Method Summary collapse
-
#auth_url ⇒ String
The authorization URL you need to redirect a HomeAway user to grant you access to their account.
-
#credentials ⇒ String
The Base64 encoded credentials for the current client.
-
#oauth_code=(code) ⇒ Boolean
completes the oauth flow.
-
#state ⇒ String
A 48 characters long, securely random string, used to mitigate CSRF attacks during the authorization process.
Instance Method Details
#auth_url ⇒ String
Returns the authorization URL you need to redirect a HomeAway user to grant you access to their account.
30 31 32 |
# File 'lib/homeaway/api/util/oauth.rb', line 30 def auth_url oauth_client_strategy.(state: state) end |
#credentials ⇒ String
Returns the Base64 encoded credentials for the current client.
24 25 26 |
# File 'lib/homeaway/api/util/oauth.rb', line 24 def credentials Base64.strict_encode64 "#{@configuration.client_id}:#{@configuration.client_secret}" end |
#oauth_code=(code) ⇒ Boolean
completes the oauth flow
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/homeaway/api/util/oauth.rb', line 43 def oauth_code=(code) begin auth_code_strategy = oauth_client_strategy token = auth_code_strategy.get_token(code, :headers => {'Authorization' => "Basic #{credentials}"}) @token = token.token @token_expires = Time.at token.expires_at @refresh_token = token.refresh_token @mode = :three_legged return true rescue => e if e.is_a? OAuth2::Error error_class = HomeAway::API::Errors.for_http_code e.response.status raise error_class.new(JSON.parse(e.response.response.body)) end raise HomeAway::API::Errors::HomeAwayAPIError.new e. end end |
#state ⇒ String
Returns a 48 characters long, securely random string, used to mitigate CSRF attacks during the authorization process.
36 37 38 |
# File 'lib/homeaway/api/util/oauth.rb', line 36 def state @_state ||= @configuration.state || SecureRandom.hex(24) end |