Class: SparkApi::Authentication::OAuth2Impl::CLIProvider
- Inherits:
-
BaseOAuth2Provider
- Object
- BaseOAuth2Provider
- SparkApi::Authentication::OAuth2Impl::CLIProvider
- Defined in:
- lib/spark_api/authentication/oauth2_impl/cli_provider.rb
Constant Summary collapse
- SESSION_FILE =
'.spark_api_oauth2'
Instance Attribute Summary collapse
-
#persistent_sessions ⇒ Object
Returns the value of attribute persistent_sessions.
-
#session_alias ⇒ Object
Returns the value of attribute session_alias.
Attributes inherited from BaseOAuth2Provider
Instance Method Summary collapse
- #destroy_session ⇒ Object
-
#initialize(credentials) ⇒ CLIProvider
constructor
A new instance of CLIProvider.
- #load_session ⇒ Object
- #persistent_sessions? ⇒ Boolean
- #redirect(url) ⇒ Object
- #save_session(session) ⇒ Object
Methods inherited from BaseOAuth2Provider
Constructor Details
#initialize(credentials) ⇒ CLIProvider
Returns a new instance of CLIProvider.
9 10 11 12 13 14 |
# File 'lib/spark_api/authentication/oauth2_impl/cli_provider.rb', line 9 def initialize(credentials) super(credentials) @grant_type = :password @persistent_sessions = false @session_alias = "default" end |
Instance Attribute Details
#persistent_sessions ⇒ Object
Returns the value of attribute persistent_sessions.
16 17 18 |
# File 'lib/spark_api/authentication/oauth2_impl/cli_provider.rb', line 16 def persistent_sessions @persistent_sessions end |
#session_alias ⇒ Object
Returns the value of attribute session_alias.
16 17 18 |
# File 'lib/spark_api/authentication/oauth2_impl/cli_provider.rb', line 16 def session_alias @session_alias end |
Instance Method Details
#destroy_session ⇒ Object
36 37 38 39 |
# File 'lib/spark_api/authentication/oauth2_impl/cli_provider.rb', line 36 def destroy_session destroy_persistent_session @session = nil end |
#load_session ⇒ Object
27 28 29 |
# File 'lib/spark_api/authentication/oauth2_impl/cli_provider.rb', line 27 def load_session() @session ||= load_persistent_session end |
#persistent_sessions? ⇒ Boolean
41 42 43 |
# File 'lib/spark_api/authentication/oauth2_impl/cli_provider.rb', line 41 def persistent_sessions? persistent_sessions == true end |
#redirect(url) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/spark_api/authentication/oauth2_impl/cli_provider.rb', line 18 def redirect(url) puts "Missing OAuth2 session, redirecting..." puts "Please visit #{url}, login as a user, and paste the authorization code here:" self.code = HighLine.ask("Authorization code?") do |q| q.whitespace = :strip_and_collapse q.validate = /^\w+$/ end end |
#save_session(session) ⇒ Object
31 32 33 34 |
# File 'lib/spark_api/authentication/oauth2_impl/cli_provider.rb', line 31 def save_session(session) @session = session save_persistent_session end |