Class: SparkApi::Authentication::OAuth2Impl::CLIProvider

Inherits:
BaseOAuth2Provider show all
Defined in:
lib/spark_api/authentication/oauth2_impl/cli_provider.rb

Constant Summary collapse

SESSION_FILE =
'.spark_api_oauth2'

Instance Attribute Summary collapse

Attributes inherited from BaseOAuth2Provider

#code, #grant_type

Instance Method Summary collapse

Methods inherited from BaseOAuth2Provider

#session_timeout

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_sessionsObject

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_aliasObject

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_sessionObject



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_sessionObject



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

Returns:

  • (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 = 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