# Valid token, unsuccessful login with tmi.js

**URL:** <https://staging-discuss.dev.twitch.com/t/valid-token-unsuccessful-login-with-tmi-js/30855>\
**Category:** Chat and IRC\
**Created:** [March 17, 2021, 12:25am UTC](https://staging-discuss.dev.twitch.com/t/valid-token-unsuccessful-login-with-tmi-js/30855 "2021-03-17T00:25:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wouter-heerwegh](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/wouter-heerwegh/32/11672_2.png) [@wouter-heerwegh](https://staging-discuss.dev.twitch.com/u/wouter-heerwegh)\
**Post date:** [March 17, 2021, 12:25am UTC](https://staging-discuss.dev.twitch.com/t/valid-token-unsuccessful-login-with-tmi-js/30855/1 "2021-03-17T00:25:56Z")

</div>

Hi everyone,

I’m trying to make a simple twitch bot and I’m trying to use an authentication flow to get my oauth token. After getting this token, I can validate it and it returns a status 200. In the response it states my client\_id.

To make sure tmi.js is not trying to connect to the server first (without any token), I’m waiting on the token with await, and this works fine.

However, when calling client.connect() on the tmi client, I get the following:  
[01:09] info: Connecting to [irc-ws.chat.twitch.tv](http://irc-ws.chat.twitch.tv) on port 443…  
[01:09] info: Sending authentication to server…  
[01:09] error: Login unsuccessful

Does anyone know why this happens and how I can solve this?

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://staging-discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [March 17, 2021, 12:35am UTC](https://staging-discuss.dev.twitch.com/t/valid-token-unsuccessful-login-with-tmi-js/30855/2 "2021-03-17T00:35:10Z")

</div>

> [@wouter-heerwegh](#):
>
> I’m trying to make a simple twitch bot and I’m trying to use an authentication flow to get my oauth token.

Which authentication flow?

Only a user access token can login to chat when authenticating as a user

- [Getting OAuth Access Tokens | Twitch Developers](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth#oauth-authorization-code-flow)
- [Getting OAuth Access Tokens | Twitch Developers](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth#oauth-client-credentials-flow)

> [@wouter-heerwegh](#):
>
> To make sure tmi.js is not trying to connect to the server first (without any token), I’m waiting on the token with await, and this works fine.

This sounds like you have used an App Access Token instead

---

<div class="post-metadata">

**Author:** ![wouter-heerwegh](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/wouter-heerwegh/32/11672_2.png) [@wouter-heerwegh](https://staging-discuss.dev.twitch.com/u/wouter-heerwegh)\
**Post date:** [March 17, 2021, 12:40am UTC](https://staging-discuss.dev.twitch.com/t/valid-token-unsuccessful-login-with-tmi-js/30855/3 "2021-03-17T00:40:38Z")

</div>

Hi Barry,

I’m indeed using an App Access Token as I would like to have my bot act on its own rather than on my behalf. So I used the client credentials flow. Is it possible to use tmi in this way? Or does it only work for users?

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://staging-discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [March 17, 2021, 12:41am UTC](https://staging-discuss.dev.twitch.com/t/valid-token-unsuccessful-login-with-tmi-js/30855/4 "2021-03-17T00:41:24Z")

</div>

The “bot” needs to exist as a “user on Twitch”

Then you go thru the user authentication flow whilst logged into the Twitch Website _as the bot_ to get the tokens you need.

---

<div class="post-metadata">

**Author:** ![system](https://d2spem0quai2ol.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://staging-discuss.dev.twitch.com/u/system)\
**Post date:** [April 16, 2021, 12:41am UTC](https://staging-discuss.dev.twitch.com/t/valid-token-unsuccessful-login-with-tmi-js/30855/5 "2021-04-16T00:41:27Z")

</div>

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