Class: FluidCLI::IdentityAuth::Servlet

Inherits:
WEBrick::HTTPServlet::AbstractServlet
  • Object
show all
Defined in:
lib/fluid_cli/identity_auth/servlet.rb

Constant Summary collapse

ERB_FILENAME =
File.join(FluidCLI::ROOT, "lib/fluid_cli/assets/post_auth_page/index.html.erb")
CSS_FILENAME =
File.join(FluidCLI::ROOT, "lib/fluid_cli/assets/post_auth_page/style.css")

Instance Method Summary collapse

Constructor Details

#initialize(server, identity_auth, token) ⇒ Servlet

Returns a new instance of Servlet.



7
8
9
10
11
# File 'lib/fluid_cli/identity_auth/servlet.rb', line 7

def initialize(server, identity_auth, token)
  super
  @server = server
  @identity_auth = identity_auth
end

Instance Method Details

#do_GET(req, res) ⇒ Object

rubocop:disable Naming/MethodName



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fluid_cli/identity_auth/servlet.rb', line 13

def do_GET(req, res) # rubocop:disable Naming/MethodName
  if !req.query["error"].nil?
    respond_with(
      res,
      400,
      req.query["error"],
    )
  else
    respond_with(res, 200, "Authentication successful! You can close this window.")
  end
  @identity_auth.response_query = req.query
  @server.shutdown
end

#respond_with(response, status, message) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/fluid_cli/identity_auth/servlet.rb', line 27

def respond_with(response, status, message)
  successful = status == 200
  locals = {
    status: status,
    message: message,
    css: File.read(CSS_FILENAME),
  }
  response.status = status
  response.body = ERB.new(File.read(ERB_FILENAME)).result(binding)
end