We are integrating Zoom OAuth and using the refresh token to get a new access token when it expires.
However, I recently received a 400
response during the refresh process, and I’m not sure why. In my function, I currently assume that any 400
response means the refresh token is expired or invalid. So, I mark the Zoom account accordingly.
Later, I found out that everything seemed fine:
- The client had connected their Zoom account just a day before.
- They didn’t remove or revoke our OAuth app.
So I’m confused why Zoom still returned a 400
response.
My questions:
- Is it correct to assume that any
400
response during token refresh means the refresh token is expired or invalid? - Are there other cases where Zoom might return
400
even if the refresh token is valid? - Did my function is correct or please suggest any more in detail
Here’s the function I’m using:
def refresh_zoom_token(zoom_account):
data = {"grant_type": "refresh_token", "refresh_token": zoom_account.refresh_token}
auth = (settings.ZOOM_CLIENT_ID, settings.ZOOM_CLIENT_SECRET)
try:
response = requests.post(
"https://zoom.us/oauth/token",
data=data,
auth=auth,
timeout=ZOOM_API_TIMEOUT,
verify=True,
)
response.raise_for_status()
except requests.exceptions.HTTPError as e:
if e.response.status_code == 400:
# Zoom says refresh_token is invalid/expired
zoom_account.mark_refresh_token_expired()
raise ZoomOAuthError("Zoom session expired. Please reconnect.")
raise
tokens = response.json()
zoom_account.update_tokens(
access_token=tokens["access_token"],
refresh_token=tokens["refresh_token"],
expires_in_seconds=tokens["expires_in"],
)