As said in title my api token for bearer auth stops working after ~ 12h
what can i do to fix that ?
If it’s implict token get a new one from the user (good for 60 days usually)
if it’s code flow token use the refresh token (the token is good for 4 hours)
if it’s app access/client creds get a new one (good for 60 days usually)
if it’s DCF we’ll discuss if you are using DCF.
The other thing that kills a token is if you generate 50, it will kill the 1st when you generate the 51st
I get it from twitch dev api website for an application project as i use it for an electron app
What should i do for it to not time out ?
Do i have to create somewhere an api to refresh the token every x if he is too old ??
Like store it in db then
request last update time
If more than 50 days request new one idk
Then send back current or new one as answer but if the app gors unised for more than 60 days i’m fcked
You got what from the Developer console?
The dev console doesn’t give you a bearer to use?
Then you should be using DCF
When the token expires, use the refresh token to get a new token.
If the refresh token doesn’t work, ask the user to login again.
Under DCF:
- user opens your app
- user logins with twitch
- you get a token good for 4 hours and a refresh token
- if your app is still open and the token dies, get a new token
- user closes your app
if the user reopens your app within 30 days then the refresh token is still valid, refresh and off we go again, or ask the user to login with twitch again.
No thats just how oAuth works.
So to explain more i just wanna embed the client’s stream ( this is not paid work just so you know ) on the electron app so i created an app on my dev profile on twitch and use it to embed the stream and check if offline what the last vod is
So there aint no logging with twitch
Just trying to embed something and i ended up needing a token for that and would have needed one for the query and vod anyway
Embeds don’t require a token or a client id
So not sure what you are doing to need ine
But they do if i dont put the toke. It asks for one in the console and i need one anyway for the last vod thingy
Will post updates with more info in lile an hour or more when i get access to work pc again
no token is required?
Where/how? Whats the error
What code are you using to embed with
As said posting back in 1h with more info when i get access again
But iirc embed everything code
in any way i need one for the retreiving of last vod if no stream is up
i may remember wrong that i need one for the embeding the still
the whole thing cannot work without the token to request last vod if no stream is up
wich is 2 requests
Then yes you need a token for that
So
- your electron app opens
- you use the refresh token for DCF if you have one and it’s valid
- if not you ask the user to login, then you have a user token and a refresh token
but i do not want ppl having to log in just for a stream embedding hence i use an app token so they dont have to …
to be more precise it’s a minecraft launcher
ppl already log in with their microsoft account
would be really bad if they had to log in too with twitch just for 2 requests
There is no way client side/in electron to generate/use a app token
As it would leak the app token or your client secret. As per the Developer Agreement
Let alone the 50 rule, the 51st user of your electron app would break/kill the 1st persons token.
The alternative is the electron app goes to fetch the video ID to embed from a remote server, and then you need no tokens at all
Without a remote server providing the video ID to embed you don’t have a choice.
but the server still would need a token for the api request no ?
Correct
But the token would be hidden from users and you wouldn’t need users of your app to login with twitch