This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Ondilo spa/pool monitor
#23
Try this:
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)

  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
  })

  local location = hdrs.location
  local auth_code = location:match('code=(%w+)')

  if not auth_code then
    return
  end

  local data = {
    'code=' .. escape(auth_code),
    'grant_type=authorization_code',
    'client_id=customer_api',
    'redirect_uri=' .. escape(uri),
  }
  local body = table.concat(data, '&')

  local resp, code, hdrs, stat = socket.http.request({
    url = apiHost .. endpointToken,
    method = 'POST',
    headers = {
      ['Content-Type'] = 'application/x-www-form-urlencoded',
      ['Content-Length'] = #body,
      ['Referer'] = url,
      ['Cookie'] = cookietoken .. '; ' .. cookiesession,
    },
    body = body
  })

  if code == 200 then
    local data = json.decode(resp)
    return data.access_token
  end
end
Reply


Messages In This Thread
Ondilo spa/pool monitor - by gjniewenhuijse - 20.10.2020, 14:46
RE: Ondilo spa/pool monitor - by admin - 22.10.2020, 06:30
RE: Ondilo spa/pool monitor - by admin - 22.10.2020, 07:14
RE: Ondilo spa/pool monitor - by admin - 22.10.2020, 08:23
RE: Ondilo spa/pool monitor - by admin - 22.10.2020, 11:24
RE: Ondilo spa/pool monitor - by admin - 23.10.2020, 06:47
RE: Ondilo spa/pool monitor - by MikeBrignate - 21.05.2021, 19:08
RE: Ondilo spa/pool monitor - by admin - 24.05.2021, 09:38
RE: Ondilo spa/pool monitor - by MikeBrignate - 25.05.2021, 07:12
RE: Ondilo spa/pool monitor - by admin - 25.05.2021, 08:19
RE: Ondilo spa/pool monitor - by function - 12.06.2025, 10:51
RE: Ondilo spa/pool monitor - by admin - 13.06.2025, 07:03
RE: Ondilo spa/pool monitor - by function - 18.06.2025, 18:03
RE: Ondilo spa/pool monitor - by admin - 20.06.2025, 07:26
RE: Ondilo spa/pool monitor - by admin - 25.06.2025, 07:06

Forum Jump: