LUA connector fails after a stream is stopped

my last hope is here. been trying a 3rd party scripts which are working just fine until the stream is stopped for few hours. After that time, if i try to use same connector to auth via Twitch, it says No Client ID, which i suppose meaning that the URL forming function doesn’t re-auth the same way as it does. Anybody here related with LUA scripting? Will much appreciate a bit help, because i’m completely lost, since the code is ‘easy’ to read, but still i’m really confused where is the exact function which fails.

Any help will be appreciated and we’ll do my best to express my gratitude once i have a plain explanation what’s wrong.
~ BR - https://pastebin.com/NNKbJ2zS

Update this:

local req_headers = {
  ['Accept'] = 'application/vnd.twitchtv.v5+json',
}

to

local req_headers = {
  ['Accept'] = 'application/vnd.twitchtv.v5+json',
  ['Client-ID'] = 'YOURCLIENTID'
}

Somewhere in your code you are making a request without an attached oAuth and thus are missing a ClientID.

if this works out for me, you’ll have my blessing and a cup of beer!

applied into dev - will report back. thanks for your effort for now

nope, again the app wasn’t able after some time to authenticate. see below the debug output of nginx errs. and the third is keep trying until the rtmp is stopped. also having and postgresql notice, and i wonder if this could be the issue

[notice] 23067#23067: *3 [lua] postgres.lua:73: select(): ^[[0m^[[1m^[[36mSQL: ^[[0m^[[35mSELECT key, value, extract(epoch from expires_at - (now() at time zone 'UTC')) as expires_in, extract(epoch from expires_at) as expires_at from keystore where account_id = 19 and stream_id = 1 and (expires_at > (now() at time zone 'UTC') or expires_at is null)^[[0m^[[0m, context: ngx.timer

2017/11/14 16:54:40 [debug] 23067#23067: *381 [lua] http.lua:631: send_request():
PUT /kraken/channels/59085056 HTTP/1.1^M
Content-Length: 90^M
User-Agent: lua-resty-http/0.11 (Lua) ngx_lua/10010^M
Accept: application/vnd.twitchtv.v5+json^M
Content-Type: application/json^M
Authorization: OAuth 2ixdxjwk7kmdmmu5rdrjzug6iqyl3c^M
Host: api.twitch.tv^M

2017/11/14 16:54:40 [debug] 23067#23067: *3 [lua] http.lua:631: send_request():
GET /kraken/user/ HTTP/1.1^M
Accept: application/vnd.twitchtv.v5+json^M
User-Agent: lua-resty-http/0.11 (Lua) ngx_lua/10010^M
Authorization: OAuth 2ixdxjwk7kmdmmu5rdrjzug6iqyl3c^M
Host: api.twitch.tv^M


2017/11/14 16:54:41 [debug] 23067#23067: *3 [lua] http.lua:631: send_request():
GET /kraken/streams/59085056 HTTP/1.1^M
Accept: application/vnd.twitchtv.v5+json^M
User-Agent: lua-resty-http/0.11 (Lua) ngx_lua/10010^M
Authorization: OAuth 2ixdxjwk7kmdmmu5rdrjzug6iqyl3c^M
Host: api.twitch.tv^M

I don’t see any ClientID in your Debug output. Try setting and sending the ClientID

Nor do I see the the rseponse from Twitch.

And you should NEVER show us your OAuth. Please revoke that OAuth immediately

revoked. thanks for noticing this. let me clarify how the url is formed. the following function is within the twitch.lua:

function M.get_oauth_url(user, stream_id)
  return format('%s/oauth2/authorize?',api_url)..
         encode_query_string({
           response_type = 'code',
           force_verify = 'true',
           redirect_uri = M.redirect_uri,
           client_id = twitch_config.client_id,
           state = encode_base64(encode_with_secret({ id = user.id, stream_id = stream_id })),
           scope = 'user_read channel_read channel_editor channel_stream chat_login',
         })

meaning that once a user authorized the app through twitch, it writes the information it gets into database. this step is fine, having the user authorizing ‘by hand’.

  local body = encode_query_string({
    client_id = twitch_config.client_id,
    client_secret = twitch_config.client_secret,
    redirect_uri = M.redirect_uri,
    code = params.code,
    state = params.state,
    refresh_token = refresh_token,
    grant_type = 'authorization_code',
  })

this generates (and encodes) the EXACT database info which should be used once a stream is up. so, basically everything goes to the following function which fails after the expiration of the refresh_token:

for _,account in pairs(self.accounts) do
          local sa = StreamAccount:find({ stream_id = self.stream.id, account_id = account.id })
          if sa then
            local rtmp_url, err = networks[account.network].publish_start(account:get_keystore(),sa:get_keystore())
            if (not rtmp_url) or err then
              self.session.status_msg = { type = 'error', msg = 'Failed to start pusher: ' .. err}
              ngx_log(ngx_warn,format(
                'app:publish-start: failed to start %s (%s): %s',
                account.name,
                networks[account.network].name,
                err
              ))
              return { redirect_to = self:url_for('stream-edit', { id = self.stream.id }) .. '?subset=dashboard' }
            end
            sa:update({rtmp_url = rtmp_url})
            insert(sas, sa)
          end
        end

i know that there is something within the code, but i’m crippled to find out :wink: again - thanks for your effort!

Why are you trying to refresh?

oAuth access tokens do not currently expire…

so the 2nd function could be only as follows? if u have a suggestion how to form the function let me know

local body = encode_query_string({
client_id = twitch_config.client_id,
client_secret = twitch_config.client_secret,
redirect_uri = M.redirect_uri,
grant_type = ‘authorization_code’,
})

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.