Skip to content

Commit

Permalink
Handle unexpected values for expires_in in OAuth Access response
Browse files Browse the repository at this point in the history
  • Loading branch information
dkirov-dd committed Jan 10, 2025
1 parent fd0bf69 commit a01e3a2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion datadog_checks_base/datadog_checks/base/utils/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,13 @@ def read(self, **request):

# https://www.rfc-editor.org/rfc/rfc6749#section-4.4.3
self._token = response['access_token']
self._expiration = get_timestamp() + response['expires_in']
self._expiration = get_timestamp()
try:
# According to https://www.rfc-editor.org/rfc/rfc6749#section-5.1, the `expires_in` field is optional
token_expiration = response.get('expires_in', 0)
self._expiration += token_expiration
except TypeError:
self.logger.warning('OAuth2 included an `expires_in` value of unexpected type %s.', type(token_expiration))

return self._token

Expand Down

0 comments on commit a01e3a2

Please sign in to comment.