Module: HomeAway::API::Util::OAuth

Included in:
Client
Defined in:
lib/homeaway/api/util/oauth.rb

Instance Method Summary collapse

Instance Method Details

#auth_urlString

Returns the authorization URL you need to redirect a HomeAway user to grant you access to their account.

Returns:

  • (String)

    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.authorize_url(state: state)
end

#credentialsString

Returns the Base64 encoded credentials for the current client.

Returns:

  • (String)

    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

Parameters:

  • code (String)

    service ticket to authenticate

Returns:

  • (Boolean)

    true if the authentication succeeded, false otherwise



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.message
  end
end

#stateString

Returns a 48 characters long, securely random string, used to mitigate CSRF attacks during the authorization process.

Returns:

  • (String)

    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