Class: Fog::Brightbox::OAuth2::CredentialSet
- Inherits:
-
Object
- Object
- Fog::Brightbox::OAuth2::CredentialSet
- Defined in:
- lib/fog/brightbox/oauth2.rb
Overview
Interface to update certain credentials (after password change)
Encapsulates credentials required to request access tokens from the Brightbox authorisation servers
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
readonly
Returns the value of attribute client_secret.
-
#expires_in ⇒ Object
readonly
Returns the value of attribute expires_in.
-
#one_time_password ⇒ Object
readonly
Returns the value of attribute one_time_password.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#refresh_token ⇒ Object
readonly
Returns the value of attribute refresh_token.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
-
#access_token? ⇒ Boolean
Is an access token available for these credentials?.
-
#best_grant_strategy ⇒ Object
Based on available credentials returns the best strategy.
-
#initialize(client_id, client_secret, options = {}) ⇒ CredentialSet
constructor
A new instance of CredentialSet.
-
#refresh_token? ⇒ Boolean
Is a refresh token available for these credentials?.
-
#update_tokens(access_token, refresh_token = nil, expires_in = nil) ⇒ Object
Updates the credentials with newer tokens.
-
#user_details? ⇒ Boolean
Returns true if user details are available.
Constructor Details
#initialize(client_id, client_secret, options = {}) ⇒ CredentialSet
Returns a new instance of CredentialSet.
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/fog/brightbox/oauth2.rb', line 73 def initialize(client_id, client_secret, = {}) @client_id = client_id @client_secret = client_secret @username = [:username] @password = [:password] @access_token = [:access_token] @refresh_token = [:refresh_token] @expires_in = [:expires_in] @one_time_password = [:one_time_password] end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
63 64 65 |
# File 'lib/fog/brightbox/oauth2.rb', line 63 def access_token @access_token end |
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
62 63 64 |
# File 'lib/fog/brightbox/oauth2.rb', line 62 def client_id @client_id end |
#client_secret ⇒ Object (readonly)
Returns the value of attribute client_secret.
62 63 64 |
# File 'lib/fog/brightbox/oauth2.rb', line 62 def client_secret @client_secret end |
#expires_in ⇒ Object (readonly)
Returns the value of attribute expires_in.
63 64 65 |
# File 'lib/fog/brightbox/oauth2.rb', line 63 def expires_in @expires_in end |
#one_time_password ⇒ Object (readonly)
Returns the value of attribute one_time_password.
64 65 66 |
# File 'lib/fog/brightbox/oauth2.rb', line 64 def one_time_password @one_time_password end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
62 63 64 |
# File 'lib/fog/brightbox/oauth2.rb', line 62 def password @password end |
#refresh_token ⇒ Object (readonly)
Returns the value of attribute refresh_token.
63 64 65 |
# File 'lib/fog/brightbox/oauth2.rb', line 63 def refresh_token @refresh_token end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
62 63 64 |
# File 'lib/fog/brightbox/oauth2.rb', line 62 def username @username end |
Instance Method Details
#access_token? ⇒ Boolean
Is an access token available for these credentials?
91 92 93 |
# File 'lib/fog/brightbox/oauth2.rb', line 91 def access_token? !!@access_token end |
#best_grant_strategy ⇒ Object
Add a means to dictate which should or shouldn’t be used
Based on available credentials returns the best strategy
111 112 113 114 115 116 117 118 119 |
# File 'lib/fog/brightbox/oauth2.rb', line 111 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?
96 97 98 |
# File 'lib/fog/brightbox/oauth2.rb', line 96 def refresh_token? !!@refresh_token end |
#update_tokens(access_token, refresh_token = nil, expires_in = nil) ⇒ Object
Updates the credentials with newer tokens
101 102 103 104 105 |
# File 'lib/fog/brightbox/oauth2.rb', line 101 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
86 87 88 |
# File 'lib/fog/brightbox/oauth2.rb', line 86 def user_details? !!(@username && @password) end |