Class: Aptible::Auth::Token
- Defined in:
- lib/aptible/auth/token.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#expires_at ⇒ Object
Returns the value of attribute expires_at.
-
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
Class Method Summary collapse
Instance Method Summary collapse
- #authenticate_client(id, secret, subject, options = {}) ⇒ Object
- #authenticate_user(email, password, options = {}) ⇒ Object
- #oauth ⇒ Object
- #process_options(options) ⇒ Object
Methods inherited from Resource
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
6 7 8 |
# File 'lib/aptible/auth/token.rb', line 6 def access_token @access_token end |
#expires_at ⇒ Object
Returns the value of attribute expires_at.
6 7 8 |
# File 'lib/aptible/auth/token.rb', line 6 def expires_at @expires_at end |
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
6 7 8 |
# File 'lib/aptible/auth/token.rb', line 6 def refresh_token @refresh_token end |
Class Method Details
.create(options) ⇒ Object
8 9 10 11 12 |
# File 'lib/aptible/auth/token.rb', line 8 def self.create() token = new token.() token end |
Instance Method Details
#authenticate_client(id, secret, subject, options = {}) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/aptible/auth/token.rb', line 20 def authenticate_client(id, secret, subject, = {}) [:scope] ||= 'manage' response = oauth.assertion.get_token({ iss: id, sub: subject }.merge(signing_params_from_secret(secret).merge())) parse_oauth_response(response) end |
#authenticate_user(email, password, options = {}) ⇒ Object
14 15 16 17 18 |
# File 'lib/aptible/auth/token.rb', line 14 def authenticate_user(email, password, = {}) [:scope] ||= 'manage' response = oauth.password.get_token(email, password, ) parse_oauth_response(response) end |
#oauth ⇒ Object
29 30 31 32 |
# File 'lib/aptible/auth/token.rb', line 29 def oauth = { site: root_url, token_url: '/tokens' } @oauth ||= OAuth2::Client.new(nil, nil, ) end |
#process_options(options) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/aptible/auth/token.rb', line 34 def () if (email = .delete(:email)) && (password = .delete(:password)) authenticate_user(email, password, ) elsif (client_id = .delete(:client_id)) && (client_secret = .delete(:client_secret)) && (subject = .delete(:subject)) authenticate_client(client_id, client_secret, subject, ) end end |