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.



7
8
9
10
11
12
# File 'lib/spark_api/authentication/oauth2_impl/cli_provider.rb', line 7

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.



14
15
16
# File 'lib/spark_api/authentication/oauth2_impl/cli_provider.rb', line 14

def persistent_sessions
  @persistent_sessions
end

#session_aliasObject

Returns the value of attribute session_alias.



14
15
16
# File 'lib/spark_api/authentication/oauth2_impl/cli_provider.rb', line 14

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



16
17
18
19
20
21
22
23
24
25
# File 'lib/spark_api/authentication/oauth2_impl/cli_provider.rb', line 16

def redirect(url)
  puts "Missing OAuth2 session, redirecting..."
  puts "Please visit #{url}, login as a user, and paste the authorization code here:"
  puts "Authorization code?"
  raw_code = gets.strip

  unless raw_code.match?(/^\w+$/)
    raise "Invalid authorization code. Please try again."
  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