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.

Has someone already integrated LG ThinQ
#7
No i have this code working with the below response. Do you think it's due to the wrong credentials or is it part of the code? ( Is still can't find any information on how to get my own credentials from LG..)

LG Thinq 08.05.2023 16:35:17
* arg: 1
  * string: {"error":{"request":"/oauth/1.0/oauth2/token","code":"LG.OAUTH.EC.2105","service":"oauth","message":"Signature doesn't match request."}}
* arg: 2
  * number: 406

Code:
require('json')
require('encdec')
require('socket.http')

OAUTH_SECRET_KEY = "c053c2a6ddeb7ad97cb0eed0dcb31cf8"
OAUTH_CLIENT_KEY = "LGAO221A02"
DATE_FORMAT = "!%a, %d %b %Y %H:%M:%S"
V2_AUTH_PATH = "/oauth/1.0/oauth2/token"

function oauth2_signature(message, secret)
  local hashed = encdec.hmacsha1(secret, message, true)
  return encdec.base64enc(hashed)
end

function auth_request(oauth_url, reqdata)
    if string.sub(oauth_url, -1):lower() == "/" then  oauth_url = string.sub(oauth_url, 0, #oauth_url-1) end
    local url = oauth_url .. V2_AUTH_PATH
    local timestamp = tostring(os.date(DATE_FORMAT, os.time())) .. " +0000"
    local data_list = {}
    for k, v in pairs(reqdata) do  table.insert(data_list, string.format("%s=%s", k, v)) end
    local req_url = string.format("%s?%s", V2_AUTH_PATH, table.concat(data_list, "&"))
    local message = string.format("%s\n%s", req_url, timestamp)
    local sig = oauth2_signature(message, OAUTH_SECRET_KEY)
    local headers = {
        ["x-lge-appkey"] = OAUTH_CLIENT_KEY,
        ["x-lge-oauth-signature"] = sig,
        ["x-lge-oauth-date"] = timestamp,
        ["Content-Type"] = "application/x-www-form-urlencoded",
        ["Accept"] = "application/json"
    }
    castdata = table.concat(data_list, "&")
    res, err = socket.http.request({
                url = url,
            headers = headers,
            data = castdata,
            method = "POST",
            timeout = 5000,
    })
end
   
local requestBody = {
    grant_type = "refresh_token",
    refresh_token = "4ed29cb48cc1cb6228658d50817b789d67d37dbad56bf561cc6389a4ab69070d8ee808edb3377ad3b07e243c467f1d36"
}

auth_request("https://nl.lgeapi.com/", requestBody)

log(res, err)
Reply


Messages In This Thread
RE: Has someone already integrated LG ThinQ - by Joep - 08.05.2023, 14:39

Forum Jump: