# OAuth client credentials flow

**URL:** <https://discuss.dev.twitch.com/t/oauth-client-credentials-flow/25392>\
**Category:** API\
**Created:** [May 5, 2020, 5:12pm UTC](https://discuss.dev.twitch.com/t/oauth-client-credentials-flow/25392 "2020-05-05T17:12:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mysterious\_Loner](https://avatars.discourse-cdn.com/v4/letter/m/77aa72/32.png) [@Mysterious\_Loner](https://discuss.dev.twitch.com/u/Mysterious_Loner)\
**Post date:** [May 5, 2020, 5:12pm UTC](https://discuss.dev.twitch.com/t/oauth-client-credentials-flow/25392/1 "2020-05-05T17:12:03Z")

</div>

I’m working on a Python script. I didn’t have too much trouble getting the ‘access\_token’ however, my only concern is how often to update and get the new token? I’m reading that I should wait until the token in near expiration, but is their a standard issue on how much time to set? It’s no problem for me to ask for a new token say every 10 minutes, 60 minutes? I just don’t know how twitch determines the amount of time until a token expires?

My initial json shows 4675259 for expiration in milliseconds, but then a second request shows 4809901; what’s the best way to set my recurring token request?

---

<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:** [May 5, 2020, 5:18pm UTC](https://discuss.dev.twitch.com/t/oauth-client-credentials-flow/25392/2 "2020-05-05T17:18:31Z")

</div>

The `expires_in` field you get given with your access token is in seconds, not milliseconds. App Access Tokens last between 50 and 70 days usually.

Usually there is no need to get a new token until hours, or a day, before it expires.

One option is to check the Validate Token endpoint [https://dev.twitch.tv/docs/authentication#validating-requests](https://dev.twitch.tv/docs/authentication#validating-requests) once a day, and check how much time is left on the token, if it’s less than a day you should get a new one.

Alternatively you can just calculate when the token is set to expire based off of the `expires_in` when you get the token, and then just regularly compare the current time to the expiration time, and that way you wont need to send a request to the Validate Token endpoint.

---

<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:** [June 4, 2020, 5:18pm UTC](https://discuss.dev.twitch.com/t/oauth-client-credentials-flow/25392/3 "2020-06-04T17:18:39Z")

</div>

Closed on June 4, 2020, 5:18pm UTC

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