Module: SparkApi::Authentication
- Included in:
- Client
- Defined in:
- lib/spark_api/authentication.rb,
lib/spark_api/authentication/oauth2.rb,
lib/spark_api/authentication/api_auth.rb,
lib/spark_api/authentication/base_auth.rb,
lib/spark_api/authentication/oauth2_impl/cli_provider.rb,
lib/spark_api/authentication/oauth2_impl/grant_type_base.rb,
lib/spark_api/authentication/oauth2_impl/grant_type_code.rb,
lib/spark_api/authentication/oauth2_impl/simple_provider.rb,
lib/spark_api/authentication/oauth2_impl/faraday_middleware.rb,
lib/spark_api/authentication/oauth2_impl/grant_type_refresh.rb,
lib/spark_api/authentication/oauth2_impl/grant_type_password.rb,
lib/spark_api/authentication/oauth2_impl/single_session_provider.rb
Overview
Authentication
Mixin module for handling client authentication and reauthentication to the spark api. Makes use of the configured authentication mode (API Auth by default).
Defined Under Namespace
Modules: OAuth2Impl Classes: ApiAuth, BaseAuth, BaseOAuth2Provider, OAuth2, OAuthSession, OpenId, OpenIdOAuth2Hybrid, Session, SimpleProvider, SingleSessionProvider
Instance Method Summary collapse
-
#authenticate ⇒ Object
Main authentication step.
-
#authenticated? ⇒ Boolean
Test to see if there is an active session.
-
#logout ⇒ Object
Delete the current session.
-
#session ⇒ Object
Fetch the active session object.
-
#session=(active_session) ⇒ Object
Save the active session object.
Instance Method Details
#authenticate ⇒ Object
Main authentication step. Run before any api request unless the user session exists and is still valid.
returns
The user session object when authentication succeeds
raises
SparkApi::ClientError when authentication fails
21 22 23 24 25 26 27 28 |
# File 'lib/spark_api/authentication.rb', line 21 def authenticate start_time = Time.now request_time = Time.now - start_time new_session = @authenticator.authenticate SparkApi.logger.info { "[#{(request_time * 1000).to_i}ms]" } SparkApi.logger.debug { "Session: #{new_session.inspect}" } new_session end |
#authenticated? ⇒ Boolean
Test to see if there is an active session
31 32 33 |
# File 'lib/spark_api/authentication.rb', line 31 def authenticated? @authenticator.authenticated? end |
#logout ⇒ Object
Delete the current session
36 37 38 39 |
# File 'lib/spark_api/authentication.rb', line 36 def logout SparkApi.logger.info { "Logging out." } @authenticator.logout end |
#session ⇒ Object
Fetch the active session object
42 43 44 |
# File 'lib/spark_api/authentication.rb', line 42 def session @authenticator.session end |
#session=(active_session) ⇒ Object
Save the active session object
46 47 48 |
# File 'lib/spark_api/authentication.rb', line 46 def session=(active_session) @authenticator.session=active_session end |