~tsileo/blobstash-app-webauthn-demo

blobstash-app-webauthn-demo/app.lua -rw-r--r-- 1.0 KiB
6f50bda1Thomas Sileo Initial commit 7 months ago
                                                                                
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
local template = require('template')
local router = require('router').new()
local wa = require('webauthn')

router:get('/', function(params)
  local js = wa.begin_registration()
  local credentials = wa.registered_credentials()
  app.response:write(template.render('register.html', 'layout.html', { js = js, credentials = credentials }))
end)

router:post('/', function(params)
  local f = app.request:form()
  local err = wa.finish_registration(f:get('data'))
  if err ~= nil then
    app.response:write(err)
  end
  app.response:redirect(url_for('/'))
end)

router:get('/login', function(params)
  local js = nil
  local credentials = wa.registered_credentials()
  if #credentials > 0 then
    js = wa.begin_login()
  end
  app.response:write(template.render('login.html', 'layout.html', { js = js, credentials = credentials }))
end)

router:post('/login', function(params)
  local f = app.request:form()
  local err = wa.finish_login(f:get('data'))
  if err ~= nil then
    app.response:write('failed')
  end
  app.response:write('ok')
end)

router:run()