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.
30 31 32 |
# File 'lib/looker-sdk/authentication.rb', line 30 def access_token_expires_at @access_token_expires_at end |
#access_token_type ⇒ Object
Returns the value of attribute access_token_type.
30 31 32 |
# File 'lib/looker-sdk/authentication.rb', line 30 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
86 87 88 |
# File 'lib/looker-sdk/authentication.rb', line 86 def application_credentials? !!application_credentials end |
#authenticate ⇒ Object
Authenticate to the server and get an access_token for use in future calls.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/looker-sdk/authentication.rb', line 49 def authenticate raise "client_id and client_secret required" unless application_credentials? set_access_token_from_params(nil) without_authentication do encoded_auth = Faraday::Utils.build_query(application_credentials) post("#{URI.parse(api_endpoint).path}/login", encoded_auth, header: {:'Content-Type' => 'application/x-www-form-urlencoded'}) 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’
33 34 35 |
# File 'lib/looker-sdk/authentication.rb', line 33 def ensure_logged_in authenticate unless token_authenticated? || @skip_authenticate end |
#logout ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/looker-sdk/authentication.rb', line 72 def logout without_authentication do result = !!@access_token && ((delete("#{URI.parse(api_endpoint).path}/logout") ; delete_succeeded?) rescue false) set_access_token_from_params(nil) result end end |
#set_access_token_from_params(params) ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/looker-sdk/authentication.rb', line 61 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
95 96 97 |
# File 'lib/looker-sdk/authentication.rb', line 95 def token_authenticated? !!(@access_token && (@access_token_expires_at.nil? || @access_token_expires_at > Time.now)) end |
#without_authentication ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/looker-sdk/authentication.rb', line 37 def without_authentication begin old_skip = @skip_authenticate || false @skip_authenticate = true yield ensure @skip_authenticate = old_skip end end |