trakt-api: Unable to refresh access tokens

I’ve been banging my head against the wall on this and I’m hoping y’all can look at logs on your side or something to illuminate the problem.

Locally, everything works fine and when a user’s access key is too old I’m able to get a new key using the refresh_key.

However in production I’m getting the following:

2019/03/19 01:42:57 Got a 401 Unauthorized, full response:
&{401 Unauthorized 401 HTTP/2.0 2 0 map[X-Frame-Options:[SAMEORIGIN] Date:[Tue, 19 Mar 2019 01:43:37 GMT] Cache-Control:[no-store] Pragma:[no-cache] Cf-Ray:[4b9bc1ab7a1720ea-LAX] Vary:[Accept-Encoding] X-Xss-Protection:[1; mode=block] Www-Authenticate:[Bearer realm="Doorkeeper", error="invalid_grant", error_description="The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client."] X-Content-Type-Options:[nosniff] X-Request-Id:[7df331ea-d463-46dd-9a1a-6308ef477da1] X-Runtime:[0.003941] Content-Type:[application/json; charset=utf-8] Content-Length:[213] Set-Cookie:[__cfduid=d6df011396a30b21c3925e7d87338f2561552959817; expires=Wed, 18-Mar-20 01:43:37 GMT; path=/; domain=.trakt.tv; HttpOnly _traktsession=MmpXUjI3Y2w5TUoySXZTS1M2Vk14RjZsU0xhTEFUbnEzNHNLR1FoamNTT0N1cmczSldsenNwT0FXQ0JGN2plTmpWb2ZLUDdBRDV1TUsxaktka2tZK3c9PS0tb1ZGVFRvcUNKSVgvSkJWd1R6a2todz09--bd643d4fefa7f60632c5c5111f47955acc595ca3; path=/; HttpOnly] Cf-Railgun:[9be4ed67ab 99.99 0.085235 0030 57da] Expect-Ct:[max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"] Server:[cloudflare]] {0xc42052c000} 213 [] false false map[] 0xc4201e8300 0xc420112370}

It scrolls to the right for quite a ways but I like to be thorough. The important bit is “The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.”

Unfortunately, this doesn’t really tell me anything useful. Since it works locally but not on production, one would think it’s probably a redirection URI problem, but initial authorization requests work fine and they use the same code for determining redirect_uri.

Specifically here is where the initial auth’s happen and here is where refreshes happen . You can find AuthRequest here.

Really it’d be super helpful just to know for what reason I’m getting the 401 unauthorized.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 17 (4 by maintainers)

Most upvoted comments

I’m running into this issue as well. I’ve always read it as the refresh_token is always valid, and then after the expires_at date is matched or exceeded I’ll refresh. I thought this worked fine but some users have reported my app not syncing and then in their logs I realize they aren’t logged in. Just came to the forums to ask about that, glad this is here though already.

This error means the original access_token has already been revoked, so the refresh_token is also invalid and can’t be used. An access_token gets revoked if the user revokes it from the Trakt website or it gets revoked once the associated refresh_token is used (basically you can’t refresh more than once).

To confirm this, I’d try creating a brand new token then refresh it and that should work. I haven’t had any other reports about this, so hopefully it is just the scenario I mentioned above.