goth icon indicating copy to clipboard operation
goth copied to clipboard

[Twitch][Gin] Can't fetch user information

Open AndriiAndrus opened this issue 5 years ago • 4 comments

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

AndriiAndrus avatar May 21 '20 23:05 AndriiAndrus

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)
		})

AndriiAndrus avatar May 21 '20 23:05 AndriiAndrus

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

gotomgo avatar May 27 '20 22:05 gotomgo

#346

stishenok avatar Jun 14 '20 11:06 stishenok

This has been merged and the issue has been resolved. This should be closed.

ghost avatar Jun 05 '21 23:06 ghost