goth
goth copied to clipboard
[Twitch][Gin] Can't fetch user information
After successful twitch sign in i was redirected to my website, the error occurred on the user fetch state. It might be GET values parsing error because i use GIN?
http://127.0.0.1:3000/auth/twitch/callback?code=codeishere777777777777&scope=user_read&state=manycharacters
Error: twitch responded with a 401 trying to fetch user information
I'm using this demo code:
authgroup.GET("/:provider/callback", func(c *gin.Context) {
provider := c.Param("provider")
// You have to add value context with provider name to get provider name in GetProviderName method
c.Request = contextWithProviderName(c, provider)
user, err := gothic.CompleteUserAuth(c.Writer, c.Request)
if err != nil {
fmt.Fprintln(c.Writer, err)
return
}
t, _ := template.New("foo").Parse(auth.UserTemplate)
t.Execute(c.Writer, user)
})
Twitch updated their OAUTH and now require that a Client-ID header appear for all helix requests.
So add this to the req in FetchUser: req.Header.Set("Client-ID", p.config.ClientID)
See here for more info: https://discuss.dev.twitch.tv/t/requiring-oauth-for-helix-twitch-api-endpoints/23916
#346
This has been merged and the issue has been resolved. This should be closed.