# Struggling with OAuth - Login unsuccessful

**URL:** <https://staging-discuss.dev.twitch.com/t/struggling-with-oauth-login-unsuccessful/27646>\
**Category:** Chat and IRC\
**Created:** [August 11, 2020, 12:19pm UTC](https://staging-discuss.dev.twitch.com/t/struggling-with-oauth-login-unsuccessful/27646 "2020-08-11T12:19:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SirAlexJz](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/siralexjz/32/20261_2.png) [@SirAlexJz](https://staging-discuss.dev.twitch.com/u/SirAlexJz)\
**Post date:** [August 11, 2020, 12:19pm UTC](https://staging-discuss.dev.twitch.com/t/struggling-with-oauth-login-unsuccessful/27646/1 "2020-08-11T12:19:02Z")

</div>

I’m trying to authenticate my bot, I’m using the tmi.js library.  
I get my token from [https://id.twitch.tv/oauth2/token](https://id.twitch.tv/oauth2/token) and I ask for the chat:read and chat:edit scopes.  
This returns ok as it should.  
I move on to validate this token via [https://id.twitch.tv/oauth2/validate](https://id.twitch.tv/oauth2/validate)  
This again returns ok as it should, so the access token should be good right?  
I pass the token to tmi.js with oauth: prepended to it like you’re supposed to. I have logged this value every step of the way to make sure it arrives correctly, which it does, so there MUST be something wrong with the token during my validation process.  
The issue is not with the connection options in tmi.js because when I pass an oauth token granted by the generator it connects just fine.  
I want to move away from the generated token as I need the experience, and will need this for more things than tmi.js can provide for me along the line.

Any help with what could possibly be going wrong will be hugely appreciated.  
Thanks.

---

<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:** [August 11, 2020, 12:21pm UTC](https://staging-discuss.dev.twitch.com/t/struggling-with-oauth-login-unsuccessful/27646/2 "2020-08-11T12:21:37Z")

</div>

Sounds like you applied for a Client Credentials

> **[Getting OAuth Access Tokens](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/)**
>
> Getting OAuth Access Tokens

instead of a User Token

> **[Getting OAuth Access Tokens](https://dev.twitch.tv/docs/authentication/getting-tokens-oauth/)**
>
> Getting OAuth Access Tokens

> [@SirAlexJz](#):
>
> I move on to validate this token via [https://id.twitch.tv/oauth2/validate](https://id.twitch.tv/oauth2/validate)

Did this return the `user_id` of your Bot in the response?

> [@SirAlexJz](#):
>
> I get my token from [https://id.twitch.tv/oauth2/token](https://id.twitch.tv/oauth2/token) and I ask for the chat:read and chat:edit scopes.  
> This returns ok as it should.

With `grant_type=client_credentials` or `&response_type=code` ?

The former won’t work for logging into Chat

Step one of “bot/user” oAuth involves redirecting the user to Twitch where they accept/decline the link between the Twitch account and your ClientID/Application

---

<div class="post-metadata">

**Author:** ![SirAlexJz](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/siralexjz/32/20261_2.png) [@SirAlexJz](https://staging-discuss.dev.twitch.com/u/SirAlexJz)\
**Post date:** [August 11, 2020, 12:47pm UTC](https://staging-discuss.dev.twitch.com/t/struggling-with-oauth-login-unsuccessful/27646/3 "2020-08-11T12:47:40Z")

</div>

Ah. Thank you. You pointed out a misconception I had.

Problem solved.

Thank you.

---

<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:** [September 10, 2020, 12:47pm UTC](https://staging-discuss.dev.twitch.com/t/struggling-with-oauth-login-unsuccessful/27646/4 "2020-09-10T12:47:42Z")

</div>

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