Class: Fog::Brightbox::OAuth2::CredentialSet

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/brightbox/oauth2.rb

Overview

TODO:

Interface to update certain credentials (after password change)

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_id, client_secret, options = {}) ⇒ CredentialSet

Returns a new instance of CredentialSet.

Parameters:

  • client_id (String)
  • client_secret (String)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :username (String)
  • :password (String)


43
44
45
46
47
48
49
50
51
# File 'lib/fog/brightbox/oauth2.rb', line 43

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

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



35
36
37
# File 'lib/fog/brightbox/oauth2.rb', line 35

def access_token
  @access_token
end

#client_idObject (readonly)

Returns the value of attribute client_id.



34
35
36
# File 'lib/fog/brightbox/oauth2.rb', line 34

def client_id
  @client_id
end

#client_secretObject (readonly)

Returns the value of attribute client_secret.



34
35
36
# File 'lib/fog/brightbox/oauth2.rb', line 34

def client_secret
  @client_secret
end

#expires_inObject (readonly)

Returns the value of attribute expires_in.



35
36
37
# File 'lib/fog/brightbox/oauth2.rb', line 35

def expires_in
  @expires_in
end

#passwordObject (readonly)

Returns the value of attribute password.



34
35
36
# File 'lib/fog/brightbox/oauth2.rb', line 34

def password
  @password
end

#refresh_tokenObject (readonly)

Returns the value of attribute refresh_token.



35
36
37
# File 'lib/fog/brightbox/oauth2.rb', line 35

def refresh_token
  @refresh_token
end

#usernameObject (readonly)

Returns the value of attribute username.



34
35
36
# File 'lib/fog/brightbox/oauth2.rb', line 34

def username
  @username
end

Instance Method Details

#access_token?Boolean

Is an access token available for these credentials?

Returns:

  • (Boolean)


60
61
62
# File 'lib/fog/brightbox/oauth2.rb', line 60

def access_token?
  !!@access_token
end

#best_grant_strategyObject

TODO:

Add a means to dictate which should or shouldn’t be used

Based on available credentials returns the best strategy



80
81
82
83
84
85
86
87
88
# File 'lib/fog/brightbox/oauth2.rb', line 80

def best_grant_strategy
  if refresh_token?
    RefreshTokenStrategy.new(self)
  elsif user_details?
    UserCredentialsStrategy.new(self)
  else
    ClientCredentialsStrategy.new(self)
  end
end

#refresh_token?Boolean

Is a refresh token available for these credentials?

Returns:

  • (Boolean)


65
66
67
# File 'lib/fog/brightbox/oauth2.rb', line 65

def refresh_token?
  !!@refresh_token
end

#update_tokens(access_token, refresh_token = nil, expires_in = nil) ⇒ Object

Updates the credentials with newer tokens



70
71
72
73
74
# File 'lib/fog/brightbox/oauth2.rb', line 70

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?Boolean

Returns true if user details are available

Returns:

  • (Boolean)


55
56
57
# File 'lib/fog/brightbox/oauth2.rb', line 55

def user_details?
  !!(@username && @password)
end