Invalid refresh_token when i try to refresh

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?

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.

1 Like

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

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

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

1 Like

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

no

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

1 Like

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