# How to connect twitch user id to my server's user id

**URL:** <https://discuss.dev.twitch.com/t/how-to-connect-twitch-user-id-to-my-servers-user-id/26551>\
**Category:** API\
**Created:** [June 19, 2020, 10:05am UTC](https://discuss.dev.twitch.com/t/how-to-connect-twitch-user-id-to-my-servers-user-id/26551 "2020-06-19T10:05:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeffrey\_Chen](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/jeffrey_chen/32/9285_2.png) [@Jeffrey\_Chen](https://discuss.dev.twitch.com/u/Jeffrey_Chen)\
**Post date:** [June 19, 2020, 10:05am UTC](https://discuss.dev.twitch.com/t/how-to-connect-twitch-user-id-to-my-servers-user-id/26551/1 "2020-06-19T10:05:40Z")

</div>

In the docs, it says

GET [https://id.twitch.tv/oauth2/authorize](https://id.twitch.tv/oauth2/authorize)  
?client\_id=  
&redirect\_uri=  
&response\_type=code  
&scope=

This will open a login page for the user, and redirect to the predefined URI after user finish auth.

My question is, if the user login on my website, and open the link, since redirect URI is predefined, I can’t put his server side user ID in it. Then how can I pass his server side user ID to the redirect URI to let my server link his twitch user ID to his server side user ID?

Is it OK to put server side user ID in the field “state”?

The docs says _ **state** _ is:

Your unique token, generated by your application. This is an OAuth 2.0 opaque value, used to avoid CSRF attacks. This value is echoed back in the response. _ **We strongly recommend you use this.** _

So I think it serves other purpose than passing data.

---

<div class="post-metadata">

**Author:** ![Dist](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/dist/32/7192_2.png) [@Dist](https://discuss.dev.twitch.com/u/Dist)\
**Post date:** [June 19, 2020, 11:05am UTC](https://discuss.dev.twitch.com/t/how-to-connect-twitch-user-id-to-my-servers-user-id/26551/2 "2020-06-19T11:05:54Z")

</div>

You can use the state for pretty much anything you like. Some use it for as your suggesting and put a token to identify that user so when they’re redirected you know who they are, some users include the path so if the user was attempting to visit `your.domain/some/path` your server can redirect them to `/some/path` after the login process. And of course there is most importantly using the state param to prevent CSRF which I HIGHLY recommend you googling yourself as there are better documentation and examples on that than what I can provide.

You can use any, or all, of those things in the state param, it’s up to you!

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [July 19, 2020, 11:05am UTC](https://discuss.dev.twitch.com/t/how-to-connect-twitch-user-id-to-my-servers-user-id/26551/3 "2020-07-19T11:05:57Z")

</div>

Closed on July 19, 2020, 11:05am UTC

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