Skip to content

Commit

Permalink
feat(socialaccount): Add timeout to requests
Browse files Browse the repository at this point in the history
  • Loading branch information
pennersr committed Dec 8, 2023
1 parent 170530a commit 0bb5032
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions ChangeLog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Note worthy changes
- Added a new app, user sessions, allowing users to view a list of all their
active sessions, as well as offering a means to end these sessions.

- A configurable timeout (``SOCIALACCOUNT_REQUESTS_TIMEOUT``) is now applied to
all upstream requests.


Backwards incompatible changes
------------------------------
Expand Down
7 changes: 6 additions & 1 deletion allauth/socialaccount/adapter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import functools
import requests
import warnings

Expand Down Expand Up @@ -293,7 +294,11 @@ def get_app(self, request, provider, client_id=None):
return apps[0]

def get_requests_session(self):
return requests.Session()
session = requests.Session()
session.request = functools.partial(
session.request, timeout=app_settings.REQUESTS_TIMEOUT
)
return session


def get_adapter(request=None):
Expand Down
4 changes: 4 additions & 0 deletions allauth/socialaccount/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ def UID_MAX_LENGTH(self):
def SOCIALACCOUNT_STR(self):
return self._setting("SOCIALACCOUNT_STR", None)

@property
def REQUESTS_TIMEOUT(self):
return self._setting("REQUESTS_TIMEOUT", 5)


_app_settings = AppSettings("SOCIALACCOUNT_")

Expand Down
3 changes: 3 additions & 0 deletions docs/socialaccount/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ Available settings:
``SOCIALACCOUNT_PROVIDERS`` (default: ``{}``)
Dictionary containing `provider specific settings <provider_configuration.html>`__.

``SOCIALACCOUNT_REQUESTS_TIMEOUT`` (default: ``5``)
The timeout applied when performing upstream requests.

``SOCIALACCOUNT_QUERY_EMAIL`` (default: ``ACCOUNT_EMAIL_REQUIRED``)
Request email address from 3rd party account provider? E.g. using
OpenID AX, or the Facebook "email" permission.
Expand Down

0 comments on commit 0bb5032

Please sign in to comment.