module Fog::Brightbox::OAuth2

This module covers Brightbox's partial implementation of OAuth 2.0 and enables fog clients to implement several authentictication strategies

@see tools.ietf.org/html/draft-ietf-oauth-v2-10

Public Instance Methods

request_access_token(connection, credentials) click to toggle source

This builds the simplest form of requesting an access token based on the arguments passed in

@param [Fog::Core::Connection] connection @param [CredentialSet] credentials

@return [Excon::Response]

# File lib/fog/brightbox/oauth2.rb, line 16
def request_access_token(connection, credentials)
  token_strategy = credentials.best_grant_strategy

  connection.request(
    :path => "/token",
    :expects  => 200,
    :headers  => token_strategy.headers,
    :method   => "POST",
    :body     => Fog::JSON.encode(token_strategy.authorization_body_data)
  )
end

Private Instance Methods

update_credentials_from_response(credentials, response) click to toggle source

This updates the current credentials if passed a valid response

@param [CredentialSet] credentials Credentials to update @param [Excon::Response] response Response object to parse value from

# File lib/fog/brightbox/oauth2.rb, line 166
def update_credentials_from_response(credentials, response)
  response_data = Fog::JSON.decode(response.body)
  credentials.update_tokens(response_data["access_token"], response_data["refresh_token"], response_data["expires_in"])
end