Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAuth AppAccessToken seemingly not getting automatically added to request headers. #45

Closed
pyorot opened this issue May 1, 2020 · 7 comments

Comments

@pyorot
Copy link

pyorot commented May 1, 2020

(Reposting because may be urgent). Hey, this doesn't seem to work as you say. I have this code:

if time.Now().After(authExpiry) {
	authExpiry = time.Now()
	res, err := twitch.GetAppAccessToken()
	exitIfError(err)
	authExpiry = authExpiry.Add(time.Duration(res.Data.ExpiresIn) * time.Second)
	log.Insta <- fmt.Sprintf("< | token generated: %s (for %ds)", res.Data.AccessToken, res.Data.ExpiresIn)
}
res, err := twitch.GetStreams(&getStreamsParams)
if err == nil && res.StatusCode != 200 {         // reinterpret HTTP error as actual error
	err = fmt.Errorf("HTTP %d: %s", res.StatusCode, res.ErrorMessage)
}
if err != nil {
	log.Insta <- fmt.Sprintf("x | < : %s", err)
}

and my program output

< | token generated: pfzn88vavmt9hlgy6c33aonf2imako (for 5444223s)
x | < : HTTP 401: OAuth token is missing

during the migration test window that just ended (is back to normal now). Any ideas?

Originally posted by @pyorot in #42 (comment)

@jackmcguire1
Copy link
Contributor

jackmcguire1 commented May 2, 2020

@pyorot hey man, you have to add the token to the twitch obj,it’s all well fetching one but you also need to use either a app access or user token, when declaring the twitch helix obj, or update the options in some way or form

@pyorot
Copy link
Author

pyorot commented May 2, 2020

Do you have a worked example? I was just following this one; I define the helix object using client ID and client secret.

@Jleagle
Copy link

Jleagle commented May 6, 2020

I just found out that this library has not been sending the Bearer token. I found out because resp.GetRateLimit() returned 30 instead of 800.

It seems a lot of oauth code has been re-written instead of using the official oauth2 package, so it doesn't quite behave the same as other packages. I wonder what happens when the app token expires?

Got it to work using this:

ops := &helix.Options{
	ClientID:     config.Config.TwitchClientID.Get(),
	ClientSecret: config.Config.TwitchClientSecret.Get(),
}

client, err = helix.NewClient(ops)
token, err := client.GetAppAccessToken()
client.SetAppAccessToken(token.Data.AccessToken)

@pyorot
Copy link
Author

pyorot commented May 6, 2020

Yeah, I also got it to work the same way, confirmed during the 2020/5/4 token requirement window. Leaving the issue open until issues #42, #44, and the usage example are updated accordingly.

@nicklaw5
Copy link
Owner

nicklaw5 commented May 6, 2020

This is already documented here.

Please open a PR if you would like to add any further documentation.

@nicklaw5 nicklaw5 closed this as completed May 6, 2020
@pyorot
Copy link
Author

pyorot commented May 14, 2020

The authentication_docs.md usage example is missing the SetAppAccessToken() line. I don't fancy forking the repo just to correct that.

@nicklaw5
Copy link
Owner

I don't fancy forking the repo just to correct that.

Then stop wasting our time, and either write your own library or use another.

Repository owner locked as too heated and limited conversation to collaborators May 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants