Lua Requires Chilkat v11.0.0+
Lua
Duo Auth API - Preauth
See more Duo Auth MFA Examples
The /preauth endpoint determines whether a user is authorized to log in, and (if so) returns the user's available authentication factors.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local integrationKey = "DIMS3V5QDVG9J9ABRXC4"
local secretKey = "HWVQ46nubLBxhnRlKddTltWIi3hL0fIQF2qTvLab"
local http = chilkat.Http.new()
http.accept = "application/json"
-- Use your own hostname here:
local url = "https://api-a03782e1.duosecurity.com/auth/v2/preauth"
http.login = integrationKey
http.password = secretKey
local req = chilkat.HttpRequest.new()
req:add_param("username", "matt")
req.http_verb = "POST"
req.content_type = "application/x-www-form-urlencoded"
local resp = chilkat.HttpResponse.new()
local success = http:http_req(url, req, resp)
if not success then
print(http.last_error_text)
return
end
print("status code = " .. resp.status_code)
local json = chilkat.JsonObject.new()
success = json:load(resp.body_str)
json.emit_compact = false
print(json:emit())
-- Sample successful output:
-- status code = 200
-- {
-- "response": {
-- "devices": [
-- {
-- "capabilities": [
-- "auto",
-- "push",
-- "sms",
-- "mobile_otp"
-- ],
-- "device": "DP6GYVTQ5NK82BMR851F",
-- "display_name": "iOS (XXX-XXX-1871)",
-- "name": "",
-- "number": "XXX-XXX-1871",
-- "type": "phone"
-- }
-- ],
-- "result": "auth",
-- "status_msg": "Account is active"
-- },
-- "stat": "OK"
-- }
-- Sample code to parse the above JSON response..
-- Use this online tool to generate parsing code from sample JSON:
-- Generate Parsing Code from JSON
local device = ""
local display_name = ""
local name = ""
local number = ""
local v_type = ""
local j = 0
local count_j = 0
local strVal = ""
local responseResult = json:string_of("response.result")
local responseStatus_msg = json:string_of("response.status_msg")
local stat = json:string_of("stat")
local i = 0
local count_i = json:size_of_array("response.devices")
while i < count_i do
json.i = i
device = json:string_of("response.devices[i].device")
display_name = json:string_of("response.devices[i].display_name")
name = json:string_of("response.devices[i].name")
number = json:string_of("response.devices[i].number")
v_type = json:string_of("response.devices[i].type")
j = 0
count_j = json:size_of_array("response.devices[i].capabilities")
while j < count_j do
json.j = j
strVal = json:string_of("response.devices[i].capabilities[j]")
j = j + 1
end
i = i + 1
end