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
#2
Ok, i give it a try

my code: 
Code:
local usr = "my@email.com"
local pwd = "mypwd"
local uri = "https%3A%2F%2Fyour.app.url%2Fauthorize" -- there's no url redirect, so how to handle this
local state = "c7d37ee542c7'" -- random

---------------------------- change nothing after this line -------------------------------

local apiHost = "https://interop.ondilo.com"
local apiUrl = apiHost .. "/api/customer/v1"
local endpointToken = "/oauth2/token"
local endpointAuth = "/oauth2/authorize"

-- init
if not init then
  require('socket.http')
  require('ltn12')
  require('json')
  socket.http.TIMEOUT = 5
  init = true
end

function getAuth()
  url = apiHost..endpointAuth..'?client_id=customer_api&response_type=code&redirect_uri='..uri..'&scope=api&state='..state
  method = "POST"
  local response_body = { } 
  local payload = '{"login":"'..usr..'","password":"'..pwd..'","locale":"nl","proceed":"Authorize"}'
 
  local res, code, response_headers, status = socket.http.request
  {
    url = url,
    method = method,
    headers =
    {
      ["Accept"] = "application/json",
      ["Accept-Charset"] = "utf-8",
      ["Accept-Encoding"] = "gzip-deflate",
      ["Content-Type"] = "application/json",
      ["Content-Length"] = payload:len()
    },
    source = ltn12.source.string(payload),
    sink = ltn12.sink.table(response_body)
  }
  log(res, code, response_headers, status)
  log(response_body)
end


getAuth()

My return:

Code:
* arg: 1
  * number: 1
* arg: 2
  * number: 200
* arg: 3
  * table:
   ["server"]
    * string: Apache/2.4.29 (Ubuntu)
   ["content-type"]
    * string: text/html;charset=UTF-8
   ["connection"]
    * string: close
   ["access-control-allow-methods"]
    * string: GET, POST, PUT, PATCH, DELETE, OPTIONS
   ["access-control-allow-headers"]
    * string: X-Requested-With, Content-Type, Accept, Origin, Authorization
   ["cache-control"]
    * string: no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0
   ["pragma"]
    * string: no-cache
   ["content-length"]
    * string: 4047
   ["date"]
    * string: Wed, 21 Oct 2020 17:45:44 GMT
   ["vary"]
    * string: Accept-Encoding
   ["access-control-allow-origin"]
    * string:
   ["access-control-allow-credentials"]
    * string: true
* arg: 4
  * string: HTTP/1.1 200 OK

but how to get the code that is normally send to the url given in the var uri (see above) or is my code wrong?

documentation is here: https://interop.ondilo.com/docs/api/cust...entication

if i do the same in a browser, my return url looks like:
https://your.app.url/authorize?code=6440...a88c&state=c7d37ee542c7
Reply


Messages In This Thread
Ondilo spa/pool monitor - by gjniewenhuijse - 20.10.2020, 14:46
RE: Ondilo spa/pool monitor - by gjniewenhuijse - 21.10.2020, 17:53
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

Forum Jump: