Yet anohter OAuth topic (sorry)

Hi everyone! I am currently trying to get an OAuth token to allow my bot to read any channel point redemptions so that I may automatically process custom channel point rewards.

I am using HTTPS to get the OAuth and ws to connect to pub/sub

HTTPS is currently not getting me the token in its response. I can however manually put it in a browser and it will show up for me in the URL (but I need to log in first).
WS is working properly with pub/sub so far, I can ping, and get a pong, but obviously I get stuck at the LISTEN type that requires an OAuth key :wink:

I’ve put my code in a hastebin to not pollute the post (hopefully this is allowed, if not feel free to delete the post and I’ll re-post it with the code directly in here)
https://hastebin.com/cocineniko.js

Part of me is worrying that I’m going about it the wrong way / going off track for what my goal is. Any help would be greatly appreciated. (I’ve seen other posts about this topic, but I couldn’t pull any information that I could use out of them.)

You have to manually follow the link to get a token. You can’t use fetch to get a user token the first time. That is the whole point of oauth is it makes the user manually authorize your apps usage. Once you get the token if you use the authorization flow you can refresh it programmatically.

You may also wish to refer to the TwitchDev github which has a “one page” example for PubSub

Gotcha that what the documentation means by refresh tokens. I will look into that, thank you for the pointer!

Hey Barry, I just tried using the sample and it puts me right back where I’m at right now except with an extra html file. I get an error cant connect page on my browser, and the auth token in the url. I’m lost on how to actually get this auth token as a response so that I may use it.

Right now even if I copy and paste that auth token from the url, I still get the bath auth error on any listen request.
Edit: this is the what I am stuck at, nothing in console.
http://localhost:3000/#access_token=(ACCESSTOKEN)j&scope=channel%3Aread%3Aredemptions&state=bdqoBSEjexWg0t5&token_type=bearer

The one page example isn’t a very production ready example.

Normally what you would probably do is setup along the lives of

  • a service/website to manage key fetching/authentication and renewal
  • a pubsub service to fetch and use those keys and relay events to whatever

Hey thanks for your response.

I saw that you have to pull the auth token out using the document.location.hash.
I will try this.
Thank you for your help!

Yeah you would do that for implict auth, but every 60 days you will need to go thru the auth flow all over again, as you didn’t get a refresh token to use to automate getting a new token

You’re right I’ll probably have to get a refresh eventually, but for now if I can get a successful response I’d call it a win.

Thanks for your help!

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