FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Unverified Commit 000d220d authored by Mike Bamford's avatar Mike Bamford Committed by GitHub
Browse files

Merge pull request #19 from rjw57/issue-18-retry-oauth2-session

add retries to OAuth2 HTTP(S) requests
parents 6ce479cf f2b4b6db
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@ from django.conf import settings
from django.contrib.auth import get_user_model
from django.core.exceptions import ObjectDoesNotExist
from rest_framework.authentication import BaseAuthentication
from requests.adapters import HTTPAdapter
from requests_oauthlib import OAuth2Session
from oauthlib.oauth2 import BackendApplicationClient, TokenExpiredError
......@@ -23,6 +24,9 @@ def _get_session():
"""
client = BackendApplicationClient(client_id=settings.LOOKUP_API_OAUTH2_CLIENT_ID)
session = OAuth2Session(client=client)
adapter = HTTPAdapter(max_retries=settings.LOOKUP_API_OAUTH2_MAX_RETRIES)
session.mount('http://', adapter)
session.mount('https://', adapter)
session.fetch_token(
timeout=2, token_url=settings.LOOKUP_API_OAUTH2_TOKEN_URL,
client_id=settings.LOOKUP_API_OAUTH2_CLIENT_ID,
......
......@@ -69,3 +69,11 @@ List of OAuth2 scopes the API server will request for the token it will use with
introspection endpoint.
"""
LOOKUP_API_OAUTH2_MAX_RETRIES = 5
"""
Maximum number of retries when fetching URLs from the OAuth2 endpoint or OAuth2 authenticated URLs.
This applies only to failed DNS lookups, socket connections and connection timeouts, never to
requests where data has made it to the server.
"""
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment