Class: FluidCLI::IdentityAuth
- Inherits:
-
Object
- Object
- FluidCLI::IdentityAuth
show all
- Defined in:
- lib/fluid_cli/identity_auth.rb,
lib/fluid_cli/identity_auth/servlet.rb
Defined Under Namespace
Classes: Error, LocalRequest, Servlet, Timeout
Constant Summary
collapse
- DEFAULT_PORT =
3456
- REDIRECT_HOST =
"http://127.0.0.1:#{DEFAULT_PORT}"
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(ctx:, store: FluidCLI::DB.new, state_token: SecureRandom.hex(30)) ⇒ IdentityAuth
Returns a new instance of IdentityAuth.
25
26
27
28
29
|
# File 'lib/fluid_cli/identity_auth.rb', line 25
def initialize(ctx:, store: FluidCLI::DB.new, state_token: SecureRandom.hex(30))
@ctx = ctx
@store = store
@state_token = state_token
end
|
Instance Attribute Details
#ctx ⇒ Object
Returns the value of attribute ctx.
23
24
25
|
# File 'lib/fluid_cli/identity_auth.rb', line 23
def ctx
@ctx
end
|
#response_query ⇒ Object
Returns the value of attribute response_query.
23
24
25
|
# File 'lib/fluid_cli/identity_auth.rb', line 23
def response_query
@response_query
end
|
#state_token ⇒ Object
Returns the value of attribute state_token.
23
24
25
|
# File 'lib/fluid_cli/identity_auth.rb', line 23
def state_token
@state_token
end
|
#store ⇒ Object
Returns the value of attribute store.
23
24
25
|
# File 'lib/fluid_cli/identity_auth.rb', line 23
def store
@store
end
|
Class Method Details
.authenticated? ⇒ Boolean
57
58
59
|
# File 'lib/fluid_cli/identity_auth.rb', line 57
def self.authenticated?
environment_auth_token? || FluidCLI::DB.exists?(:jwt)
end
|
.delete_tokens_and_keys ⇒ Object
82
83
84
|
# File 'lib/fluid_cli/identity_auth.rb', line 82
def self.delete_tokens_and_keys
FluidCLI::DB.del(:jwt)
end
|
.environment_auth_token? ⇒ Boolean
53
54
55
|
# File 'lib/fluid_cli/identity_auth.rb', line 53
def self.environment_auth_token?
!!Environment.auth_token
end
|
Instance Method Details
#attempt_reauthenticate ⇒ Object
66
67
68
|
# File 'lib/fluid_cli/identity_auth.rb', line 66
def attempt_reauthenticate
refresh_jwt
end
|
#authenticate(spinner: false) ⇒ Object
31
32
33
34
35
36
37
38
39
|
# File 'lib/fluid_cli/identity_auth.rb', line 31
def authenticate(spinner: false)
initiate_authentication
begin
store.set(jwt: receive_jwt)
rescue IdentityAuth::Timeout => e
ctx.abort(e.message)
end
end
|
#reauthenticate ⇒ Object
61
62
63
64
|
# File 'lib/fluid_cli/identity_auth.rb', line 61
def reauthenticate
return if attempt_reauthenticate
ctx.abort("Authentication required. Please login again using 'fluid_cli login' command.")
end
|
#server ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/fluid_cli/identity_auth.rb', line 70
def server
@server ||= begin
server = WEBrick::HTTPServer.new(
Port: DEFAULT_PORT,
Logger: WEBrick::Log.new(File.open(File::NULL, "w")),
AccessLog: [],
)
server.mount("/", Servlet, self, state_token)
server
end
end
|
#with_spinner(spinner, message, &block) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/fluid_cli/identity_auth.rb', line 41
def with_spinner(spinner, message, &block)
result = nil
if spinner
CLI::UI::Spinner.spin(message) do
result = block.call
end
else
result = block.call
end
result
end
|