22.10.2020, 08:16
(22.10.2020, 07:14)admin Wrote: For auth you need to use standard POST, not JSON:
For this request Accept/Content-Type headers are not needed. Add redirect = false to the request table to catch the redirect URL instead of following it.
mmm same result with changed code
Code:
function getAuth()
function encodepost(t)
local res = {}
local esc = require('socket.url').escape
for k, v in pairs(t) do
res[ #res + 1 ] = esc(k) .. '=' .. esc(v)
end
return table.concat(res, '&')
end
url = apiHost..endpointAuth..'?client_id=customer_api&response_type=code&redirect_uri='..uri..'&scope=api&state='..state
method = "POST"
local response_body = {}
local payload = encodepost({
login = usr,
password = pwd,
locale = "nl",
proceed = "Authorize",
})
local res, code, response_headers, status = socket.http.request
{
url = url,
method = method,
redirect = false,
headers =
{
["Content-Length"] = #payload
},
source = ltn12.source.string(payload),
sink = ltn12.sink.table(response_body)
}
if res and code == 200 then
log(response_body)
log(res, code, response_headers, status)
else
log(res, code, response_headers, status)
end
end