21.10.2020, 17:53
(This post was last modified: 21.10.2020, 18:29 by gjniewenhuijse.)
Ok, i give it a try
my code:
My return:
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
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