File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import logging
2+ import string
23import secrets # Python's secure random number generator module
34import base64 # For encoding binary data as text
45from oauth2_provider .models import get_application_model
5- from testbed .core .utils .utils import random_client_id , random_client_secret
66
77logger = logging .getLogger (__name__ )
88Application = get_application_model ()
2020TOKEN_EXPIRY_SESSION_KEY = 'lola_token_expiry'
2121TOKEN_SCOPE_SESSION_KEY = 'lola_token_scope'
2222
23+
24+ def random_client_id (length = 10 ):
25+ """Generate a random alphanumeric OAuth client ID of the given length."""
26+ return '' .join (secrets .choice (string .ascii_letters + string .digits ) for _ in range (length ))
27+
28+
29+ def random_client_secret (length = 40 ):
30+ """Generate a random alphanumeric OAuth client secret of the given length."""
31+ return '' .join (secrets .choice (string .ascii_letters + string .digits ) for _ in range (length ))
32+
33+
2334# Get or create the single OAuth Application for a user.
2435# This enforces the one-application-per-user approach where each user
2536# represents an ActivityPub service in the LOLA portability flow.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 2222from django .urls import reverse
2323import logging
2424import requests
25- from django .urls import reverse
2625from django .conf import settings
2726from functools import wraps
2827
@@ -769,7 +768,12 @@ def test_token_exchange_view(request):
769768 context ['token_error' ] = f"Error: { error_details .get ('error' , 'Unknown error' )} "
770769 if 'error_description' in error_details :
771770 context ['token_error' ] += f" - { error_details ['error_description' ]} "
772- except :
771+ except (ValueError , KeyError ):
772+ # ValueError catches JSONDecodeError (response body is not valid JSON).
773+ # KeyError is included defensively; in practice it cannot fire here
774+ # because error_details['error_description'] is guarded by the 'in' check above.
775+ # Note: AttributeError/TypeError (non-dict JSON) fall through to the outer
776+ # except Exception handler at the call site with a less precise error message.
773777 logger .warning (f"Response text: { token_response .text } " )
774778 context ['token_error' ] = f"Error: HTTP { token_response .status_code } - { token_response .text } "
775779
You can’t perform that action at this time.
0 commit comments