Module: LookerSDK::Authentication
- Included in:
- Client
- Defined in:
- lib/looker-sdk/authentication.rb
Overview
Authentication methods for Client
Instance Attribute Summary collapse
-
#access_token_expires_at ⇒ Object
Returns the value of attribute access_token_expires_at.
-
#access_token_type ⇒ Object
Returns the value of attribute access_token_type.
Instance Method Summary collapse
-
#application_credentials? ⇒ Boolean
Indicates if the client has OAuth Application client_id and client_secret credentials.
-
#authenticate ⇒ Object
Authenticate to the server and get an access_token for use in future calls.
-
#ensure_logged_in ⇒ Object
This is called automatically by ‘request’.
- #logout ⇒ Object
- #set_access_token_from_params(params) ⇒ Object
-
#token_authenticated? ⇒ Boolean
Indicates if the client has an OAuth access token.
- #without_authentication ⇒ Object
Instance Attribute Details
#access_token_expires_at ⇒ Object
Returns the value of attribute access_token_expires_at.
6 7 8 |
# File 'lib/looker-sdk/authentication.rb', line 6 def access_token_expires_at @access_token_expires_at end |
#access_token_type ⇒ Object
Returns the value of attribute access_token_type.
6 7 8 |
# File 'lib/looker-sdk/authentication.rb', line 6 def access_token_type @access_token_type end |
Instance Method Details
#application_credentials? ⇒ Boolean
Indicates if the client has OAuth Application client_id and client_secret credentials
61 62 63 |
# File 'lib/looker-sdk/authentication.rb', line 61 def application_credentials? !!application_credentials end |
#authenticate ⇒ Object
Authenticate to the server and get an access_token for use in future calls.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/looker-sdk/authentication.rb', line 25 def authenticate raise "client_id and client_secret required" unless application_credentials? set_access_token_from_params(nil) without_authentication do post('/login', {}, :query => application_credentials) raise "login failure #{last_response.status}" unless last_response.status == 200 set_access_token_from_params(last_response.data) end end |
#ensure_logged_in ⇒ Object
This is called automatically by ‘request’
9 10 11 |
# File 'lib/looker-sdk/authentication.rb', line 9 def ensure_logged_in authenticate unless token_authenticated? || @skip_authenticate end |
#logout ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/looker-sdk/authentication.rb', line 47 def logout without_authentication do result = !!@access_token && ((delete('/logout') ; delete_succeeded?) rescue false) set_access_token_from_params(nil) result end end |
#set_access_token_from_params(params) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/looker-sdk/authentication.rb', line 36 def set_access_token_from_params(params) reset_agent if params @access_token = params[:access_token] @access_token_type = params[:token_type] @access_token_expires_at = Time.now + params[:expires_in] else @access_token = @access_token_type = @access_token_expires_at = nil end end |
#token_authenticated? ⇒ Boolean
Indicates if the client has an OAuth access token
70 71 72 |
# File 'lib/looker-sdk/authentication.rb', line 70 def token_authenticated? !!(@access_token && (@access_token_expires_at.nil? || @access_token_expires_at > Time.now)) end |
#without_authentication ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/looker-sdk/authentication.rb', line 13 def without_authentication begin old_skip = @skip_authenticate || false @skip_authenticate = true yield ensure @skip_authenticate = old_skip end end |