Class: CloudRailSi::RedirectReceivers

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudrail_si/RedirectReceivers.rb

Constant Summary collapse

@@default_html =
'<h2>Authentication successful, you can close this window now</h2>'

Class Method Summary collapse

Class Method Details

.get_local_authenticator(port = 12345, resp_html = @@default_html) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cloudrail_si/RedirectReceivers.rb', line 9

def self.get_local_authenticator(port=12345, resp_html=@@default_html)
    return lambda { |url, state|
        Launchy.open(url)

        server = TCPServer.new('localhost', port)
        loop do
            begin
                socket = server.accept
                request = socket.gets

                STDERR.puts request

                socket.print "HTTP/1.1 200 OK\r\n" +
                             "Content-Type: text/html\r\n" +
                             "Content-Length: #{resp_html.bytesize}\r\n" +
                             "Connection: close\r\n"

                socket.print "\r\n"

                socket.print resp_html
                socket.close
                return request.split(' ')[1]
            rescue => ex
                socket.close
                raise ex
                break
            end
        end
    }
end