# Invalid refresh\_token when i try to refresh

**URL:** <https://discuss.dev.twitch.com/t/invalid-refresh-token-when-i-try-to-refresh/29748>\
**Category:** API\
**Created:** [January 2, 2021, 3:52pm UTC](https://discuss.dev.twitch.com/t/invalid-refresh-token-when-i-try-to-refresh/29748 "2021-01-02T15:52:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alessio\_Bonanni](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/alessio_bonanni/32/11035_2.png) [@Alessio\_Bonanni](https://discuss.dev.twitch.com/u/Alessio_Bonanni)\
**Post date:** [January 2, 2021, 3:52pm UTC](https://discuss.dev.twitch.com/t/invalid-refresh-token-when-i-try-to-refresh/29748/1 "2021-01-02T15:52:32Z")

</div>

hi, i have a problem.  
when i try to refresh an access token i get  
{“status”:400,“message”:“Invalid refresh token”}

i am using laravel and therefore php  
this is the request I make

> ```
> $query = 'https://id.twitch.tv/oauth2/token';
> 
> $result = Http::withHeaders(
> 
> $this->header
> 
> )->post($query,[
> 
> 'grant_type' => 'refresh_token',
> 
> 'refresh_token' => urlencode($refresh_token),
> 
> 'client_id' => $this->client_id,
> 
> 'client_secret' => $this->client_secret
> 
> ]);
> 
> ```

this used to work correctly now this problem occurs from time to time for no apparent reason  
if I connect the twitch account again for a short time it will work again

can you help me?

---

<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:** [January 2, 2021, 4:06pm UTC](https://discuss.dev.twitch.com/t/invalid-refresh-token-when-i-try-to-refresh/29748/2 "2021-01-02T16:06:43Z")

</div>

If it works some of the time, it sounds like you’re not storing the new refresh token each time and attempting to use the old refresh token which may work initially but if the refresh tokens change it’ll fail.

---

<div class="post-metadata">

**Author:** ![Alessio\_Bonanni](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/alessio_bonanni/32/11035_2.png) [@Alessio\_Bonanni](https://discuss.dev.twitch.com/u/Alessio_Bonanni)\
**Post date:** [January 2, 2021, 4:24pm UTC](https://discuss.dev.twitch.com/t/invalid-refresh-token-when-i-try-to-refresh/29748/3 "2021-01-02T16:24:51Z")

</div>

hi, thanks for the reply  
when I get a new access token I already check if the refresh token has changed and save the new one.  
I try to see if there is an error in saving in the database

---

<div class="post-metadata">

**Author:** ![Alessio\_Bonanni](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/alessio_bonanni/32/11035_2.png) [@Alessio\_Bonanni](https://discuss.dev.twitch.com/u/Alessio_Bonanni)\
**Post date:** [January 2, 2021, 5:46pm UTC](https://discuss.dev.twitch.com/t/invalid-refresh-token-when-i-try-to-refresh/29748/4 "2021-01-02T17:46:40Z")

</div>

i tried to refreshare the token several times to see if the refresh\_token changed this is the result

> {“access\_token”:“v7x…”,“expires\_in”:13630,“refresh\_token”:“ncc2wl63xp1lr8xgzf…”,“scope”:[“channel:read:subscriptions”],“token\_type”:“bearer”}  
> {“access\_token”:“tq3…”,“expires\_in”:13552,“refresh\_token”:“ncc2wl63xp1lr8xgzf…”,“scope”:[“channel:read:subscriptions”],“token\_type”:“bearer”}  
> {“access\_token”:“wzk…”,“expires\_in”:13293,“refresh\_token”:“ncc2wl63xp1lr8xgzf…”,“scope”:[“channel:read:subscriptions”],“token\_type”:“bearer”}  
> {“access\_token”:“bde…”,“expires\_in”:14201,“refresh\_token”:“ncc2wl63xp1lr8xgzf…”,“scope”:[“channel:read:subscriptions”],“token\_type”:“bearer”}  
> {“access\_token”:“nh4…”,“expires\_in”:15573,“refresh\_token”:“ncc2wl63xp1lr8xgzf…”,“scope”:[“channel:read:subscriptions”],“token\_type”:“bearer”}  
> {“access\_token”:“yqb…”,“expires\_in”:15658,“refresh\_token”:“ncc2wl63xp1lr8xgzf…”,“scope”:[“channel:read:subscriptions”],“token\_type”:“bearer”}  
> {“access\_token”:“xzi…”,“expires\_in”:14068,“refresh\_token”:“ncc2wl63xp1lr8xgzf…”,“scope”:[“channel:read:subscriptions”],“token\_type”:“bearer”}  
> {“access\_token”:“g53…”,“expires\_in”:14797,“refresh\_token”:“ncc2wl63xp1lr8xgzf…”,“scope”:[“channel:read:subscriptions”],“token\_type”:“bearer”}  
> {“access\_token”:“qpw…”,“expires\_in”:13637,“refresh\_token”:“ncc2wl63xp1lr8xgzf…”,“scope”:[“channel:read:subscriptions”],“token\_type”:“bearer”}  
> {“access\_token”:“wgo…”,“expires\_in”:15390,“refresh\_token”:“ncc2wl63xp1lr8xgzf…”,“scope”:[“channel:read:subscriptions”],“token\_type”:“bearer”}  
> {“status”:400,“message”:“Invalid refresh token”}

as you can see the refresh token always remains the same but becomes invalid

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [January 3, 2021, 11:24am UTC](https://discuss.dev.twitch.com/t/invalid-refresh-token-when-i-try-to-refresh/29748/5 "2021-01-03T11:24:55Z")

</div>

There are other cirteria that can killed a refresh token.

If you generate 25 brand new tokens, (access token/refresh token pair by clientID)  
When you generate the 26th it’ll kill the first set.

This might be what is happening here.

But since there is never a reason given for a dead refresh token, it could be a bunch of different things

---

<div class="post-metadata">

**Author:** ![Alessio\_Bonanni](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/alessio_bonanni/32/11035_2.png) [@Alessio\_Bonanni](https://discuss.dev.twitch.com/u/Alessio_Bonanni)\
**Post date:** [January 3, 2021, 11:33am UTC](https://discuss.dev.twitch.com/t/invalid-refresh-token-when-i-try-to-refresh/29748/6 "2021-01-03T11:33:36Z")

</div>

hi thanks for your reply  
is there a page in the documentation that lists the possible reasons?

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [January 3, 2021, 1:05pm UTC](https://discuss.dev.twitch.com/t/invalid-refresh-token-when-i-try-to-refresh/29748/7 "2021-01-03T13:05:25Z")

</div>

> [@Alessio\_Bonanni](#):
>
> is there a page in the documentation that lists the possible reasons?

no

---

<div class="post-metadata">

**Author:** ![merggdev](https://avatars.discourse-cdn.com/v4/letter/m/c68b51/32.png) [@merggdev](https://discuss.dev.twitch.com/u/merggdev)\
**Post date:** [January 5, 2021, 3:20am UTC](https://discuss.dev.twitch.com/t/invalid-refresh-token-when-i-try-to-refresh/29748/8 "2021-01-05T03:20:12Z")

</div>

im having the same issue. i too am saving the new refresh token and cant find anything wrong with my flow

I’ve validated that the reasons @BarryCarlyon has listed are not the culprits

---

<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:** [February 4, 2021, 3:20am UTC](https://discuss.dev.twitch.com/t/invalid-refresh-token-when-i-try-to-refresh/29748/9 "2021-02-04T03:20:18Z")

</div>

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