class Fog::Brightbox::OAuth2::CredentialSet

Encapsulates credentials required to request access tokens from the Brightbox authorisation servers

@todo Interface to update certain credentials (after password change)

Attributes

access_token[R]
client_id[R]
client_secret[R]
expires_in[R]
password[R]
refresh_token[R]
username[R]

Public Class Methods

new(client_id, client_secret, options = {}) click to toggle source

@param [String] #client_id @param [String] #client_secret @param [Hash] options @option options [String] :username @option options [String] :password

# File lib/fog/brightbox/oauth2.rb, line 48
def initialize(client_id, client_secret, options = {})
  @client_id     = client_id
  @client_secret = client_secret
  @username      = options[:username]
  @password      = options[:password]
  @access_token  = options[:access_token]
  @refresh_token = options[:refresh_token]
  @expires_in    = options[:expires_in]
end

Public Instance Methods

access_token?() click to toggle source

Is an access token available for these credentials?

# File lib/fog/brightbox/oauth2.rb, line 65
def access_token?
  !!@access_token
end
best_grant_strategy() click to toggle source

Based on available credentials returns the best strategy

@todo Add a means to dictate which should or shouldn't be used

# File lib/fog/brightbox/oauth2.rb, line 85
def best_grant_strategy
  if refresh_token?
    RefreshTokenStrategy.new(self)
  elsif user_details?
    UserCredentialsStrategy.new(self)
  else
    ClientCredentialsStrategy.new(self)
  end
end
refresh_token?() click to toggle source

Is a refresh token available for these credentials?

# File lib/fog/brightbox/oauth2.rb, line 70
def refresh_token?
  !!@refresh_token
end
update_tokens(access_token, refresh_token = nil, expires_in = nil) click to toggle source

Updates the credentials with newer tokens

# File lib/fog/brightbox/oauth2.rb, line 75
def update_tokens(access_token, refresh_token = nil, expires_in = nil)
  @access_token  = access_token
  @refresh_token = refresh_token
  @expires_in    = expires_in
end
user_details?() click to toggle source

Returns true if user details are available @return [Boolean]

# File lib/fog/brightbox/oauth2.rb, line 60
def user_details?
  !!(@username && @password)
end