# Confused about authorization token expiring

**URL:** <https://staging-discuss.dev.twitch.com/t/confused-about-authorization-token-expiring/43258>\
**Category:** API\
**Created:** [February 2, 2023, 2:56pm UTC](https://staging-discuss.dev.twitch.com/t/confused-about-authorization-token-expiring/43258 "2023-02-02T14:56:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![MrAmericanMike](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/mramericanmike/32/9502_2.png) [@MrAmericanMike](https://staging-discuss.dev.twitch.com/u/MrAmericanMike)\
**Post date:** [February 2, 2023, 2:56pm UTC](https://staging-discuss.dev.twitch.com/t/confused-about-authorization-token-expiring/43258/1 "2023-02-02T14:56:42Z")

</div>

I’m following this documentation in order to get an access token that I can use with the “tmi.js” library. This library requires a username and an oauth token.

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

The token I will have to use it, first to get the username and then finally be able to create the tmi.js instance to connect to a channel.

What I don’t understand is that the token has expiration (I know I can generate a token at [Twitch Chat Password Generator](https://twitchapps.com/tmi/) that wont expire)

So how do I generate a token that doesn’t expire?

---

<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:** [February 2, 2023, 3:35pm UTC](https://staging-discuss.dev.twitch.com/t/confused-about-authorization-token-expiring/43258/2 "2023-02-02T15:35:41Z")

</div>

> [@MrAmericanMike](#):
>
> What I don’t understand is that the token has expiration (I know I can generate a token at [Twitch Chat Password Generator](https://twitchapps.com/tmi/) that wont expire)

You don’t

all tokens expire.

You would normally _NEVER EVER USE SOMEONE ELSES GENERATOR EVER FOR PRODUCTION_

And create you own oAuth flow.  
This lets you use `code flow` to get an access and refresh token.  
Then you would use the refresh token to get a new access token

---

<div class="post-metadata">

**Author:** ![MrAmericanMike](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/mramericanmike/32/9502_2.png) [@MrAmericanMike](https://staging-discuss.dev.twitch.com/u/MrAmericanMike)\
**Post date:** [February 4, 2023, 8:00pm UTC](https://staging-discuss.dev.twitch.com/t/confused-about-authorization-token-expiring/43258/3 "2023-02-04T20:00:06Z")

</div>

But the ones generated by that website last “A lot” I mean, I think I have had those oauth tokens on some accounts and they have been working for 30 days +

Wont the ones generated with the Authorization code grant flow expire after about 4 hours.

I’m guessing for this case I can use the Implicit grant flow (I though this one was short lived) but apparently no. It’s different from other platforms. In Twitch case, this one doesn’t mention any expiration at all. Which is weird.

---

<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:** [February 4, 2023, 8:02pm UTC](https://staging-discuss.dev.twitch.com/t/confused-about-authorization-token-expiring/43258/4 "2023-02-04T20:02:17Z")

</div>

> [@MrAmericanMike](#):
>
> But the ones generated by that website last “A lot” I mean, I think I have had those oauth tokens on some accounts and they have been working for 30 days +

legacy client ID. Infinte length tokens are not the “normal” way of things existing.

> [@MrAmericanMike](#):
>
> Wont the ones generated with the Authorization code grant flow expire after about 4 hours.

And come with a refresh token to use meaning you can continue to operate

> [@MrAmericanMike](#):
>
> I’m guessing for this case I can use the Implicit grant flow (I though this one was short lived) but apparently no.

Implict and client creds are around 60 days  
Regular code flow is 4 hours, refreshable, so in theory, infinite

> [@MrAmericanMike](#):
>
> In Twitch case, this one doesn’t mention any expiration at all. Which is weird.

What doesn’t mention expiration this is unclear.

---

<div class="post-metadata">

**Author:** ![MrAmericanMike](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/mramericanmike/32/9502_2.png) [@MrAmericanMike](https://staging-discuss.dev.twitch.com/u/MrAmericanMike)\
**Post date:** [February 4, 2023, 8:14pm UTC](https://staging-discuss.dev.twitch.com/t/confused-about-authorization-token-expiring/43258/5 "2023-02-04T20:14:22Z")

</div>

> [@BarryCarlyon](#):
>
> What doesn’t mention expiration this is unclear.

The response that comes from an Implicit doesn’t come with “expires\_in”

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

```auto
http://localhost:3000/
    #access_token=73d0f8mkabpbmjp921asv2jaidwxn
    &scope=channel%3Amanage%3Apolls+channel%3Aread%3Apolls
    &state=c3ab8aa609ea11e793ae92361f002671
    &token_type=bearer

```

Will experiment with the one that lasts 4 hours and see what happens after been connected 4 hours to a channel, if it still can send messages or a “re-authorization” needs to happen causing the bot to disconnect from chat missing commands during that process.

---

<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:** [February 4, 2023, 8:15pm UTC](https://staging-discuss.dev.twitch.com/t/confused-about-authorization-token-expiring/43258/6 "2023-02-04T20:15:27Z")

</div>

> [@MrAmericanMike](#):
>
> The response that comes from an Implicit doesn’t come with “expires\_in”

Then call the validate token endpoint to fetch it.

I would have to check, but I believe it’s part of the spec not to return expiration here for this token type.

> [@MrAmericanMike](#):
>
> Will experiment with the one that lasts 4 hours and see what happens after been connected 4 hours to a channel, if it still can send messages or a “re-authorization” needs to happen causing the bot to disconnect from chat missing commands during that process.

You won’t need to reconnect as the bot won’t get kicked when the token dies.

But you will need to regenerate the token in order to ban/timeout/other actions via the API.

---

<div class="post-metadata">

**Author:** ![MrAmericanMike](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/mramericanmike/32/9502_2.png) [@MrAmericanMike](https://staging-discuss.dev.twitch.com/u/MrAmericanMike)\
**Post date:** [February 4, 2023, 8:17pm UTC](https://staging-discuss.dev.twitch.com/t/confused-about-authorization-token-expiring/43258/7 "2023-02-04T20:17:30Z")

</div>

> [@BarryCarlyon](#):
>
> You won’t need to reconnect as the bot won’t get kicked when the token dies.
> 
> But you will need to regenerate the token in order to ban/timeout/other actions via the API.

Oh good to know. Thanks a lot Barry.

---

<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:** [March 6, 2023, 8:18pm UTC](https://staging-discuss.dev.twitch.com/t/confused-about-authorization-token-expiring/43258/8 "2023-03-06T20:18:11Z")

</div>

Closed on March 6, 2023, 8:18pm UTC

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