nicklaw5 / helix

A Twitch Helix API client written in Go.
MIT License
243 stars 88 forks source link

Helix OAUTH token on all endpoints #42

Closed jackmcguire1 closed 4 years ago

jackmcguire1 commented 4 years ago

https://discuss.dev.twitch.tv/t/requiring-oauth-for-helix-twitch-api-endpoints/23916

Can we add the app access token easily to the headers?

jackmcguire1 commented 4 years ago

we apply app access token or user access token automatically before sending requests...

nicklaw5 commented 4 years ago

Yep, we already do this by default: https://github.com/nicklaw5/helix/blob/master/helix.go#L383-L393

pyorot commented 4 years ago

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?