13.06.2025, 07:03
Try this as a starting point to get the token:
Code:
function getAuth()
local url = apiHost..endpointAuth..'?client_id=customer_api&response_type=code&redirect_uri='..uri..'&scope=api&state='..state
local resp, code, hdrs, stat = socket.http.request(url = url)
local formtoken = resp:match('name="_token" value="([^"]+)">')
local cookies = hdrs['set-cookie'] or ''
local cookietoken = cookies:match('XSRF%-TOKEN=[^;]+') or ''
local cookiesession = cookies:match('interop_new_api_session=[^;]+') or ''
local escape = require('socket.url').escape
local data = {
'_token=' .. formtoken,
'email=' .. escape(usr),
'password=' .. escape(pwd),
'locale=en',
'proceed=Authorize'
}
local body = table.concat(data, '&')
local resp, code, hdrs, stat = socket.http.request({
url = url,
method = 'POST',
headers = {
['Content-Type'] = 'application/x-www-form-urlencoded',
['Content-Length'] = #body,
['Referer'] = url,
['Cookie'] = cookietoken .. '; ' .. cookiesession,
},
body = body
})
log(resp)
log(code)
log(hdrs)
end