This repository has been archived by the owner on Jul 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
server.rb
59 lines (55 loc) · 1.92 KB
/
server.rb
1
2
3
4
5
6
7
8
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require 'thin'
require 'duo_web'
puts(Rack::File.new('.'))
# Endpoint / view handler for responding to 2FA auth request and response.
class DuoLoginAdapter
def initialize
@host = ''
@ikey = ''
@skey = ''
@akey = ''
@username = ''
end
def call(env)
request = Rack::Request.new(env)
if request.get?
sig_request = Duo.sign_request(@ikey, @skey, @akey, @username)
body = ["
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<title>Duo Authentication</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<link rel='stylesheet' type='text/css' href='css/Duo-Frame.css'>
</head>
<body>
<h1>Duo Authentication</h1>
<form method='POST' id='duo_form'>
</form>
<iframe id='duo_iframe'
title='Two-Factor Authentication'
frameborder='0'
data-host='#{@host}'
data-sig-request='#{sig_request}'>
</iframe>
<script src='js/Duo-Web-v2.js'></script>
</body>
</html>
"]
elsif request.post?
sig_response = request.params['sig_response']
duo_user = Duo.verify_response(@ikey,
@skey,
@akey,
sig_response)
body = ["Auth Success! #{duo_user} is authenticated."]
end
[ 200, { 'Content-Type' => 'text/html' }, body ]
end
end
app = Rack::URLMap.new('/' => DuoLoginAdapter.new,
'/js' => Rack::File.new('./js'),
'/css' => Rack::File.new('./css'))
Thin::Server.start('0.0.0.0', 3000, app)