Skip to content

Commit d06755e

Browse files
committed
Added tests and tweaks.
1 parent 201aa8f commit d06755e

2 files changed

Lines changed: 481 additions & 11 deletions

File tree

src/datacustomcode/auth.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,10 @@ def _run_oauth_callback_server(
8383
Tuple of (server instance, actual port number)
8484
"""
8585
parsed_uri = urlparse(redirect_uri)
86-
host = parsed_uri.hostname or "localhost"
87-
port = parsed_uri.port or 5555
86+
host = parsed_uri.hostname
87+
port = parsed_uri.port
88+
if not host or not port:
89+
raise ValueError(f"Invalid redirect URI: {redirect_uri}")
8890

8991
# Create a custom handler factory
9092
def handler_factory(*args, **kwargs):
@@ -146,7 +148,7 @@ def _exchange_code_for_tokens(
146148
) from e
147149

148150

149-
def perform_oauth_browser_flow(
151+
def do_oauth_browser_flow(
150152
login_url: str, client_id: str, client_secret: str, redirect_uri: str
151153
) -> tuple[str, str]:
152154
"""Perform OAuth browser flow to obtain tokens.
@@ -163,13 +165,6 @@ def perform_oauth_browser_flow(
163165
Raises:
164166
click.ClickException: If OAuth flow fails
165167
"""
166-
# Parse redirect_uri and ensure it has a port
167-
parsed_redirect = urlparse(redirect_uri)
168-
if not parsed_redirect.port:
169-
# If no port specified, default to 5555 and update redirect_uri
170-
default_port = 5555
171-
redirect_uri = f"{parsed_redirect.scheme}://{parsed_redirect.hostname}:{default_port}{parsed_redirect.path}"
172-
173168
# Create queue for communication between server and main thread
174169
auth_code_queue: queue.Queue[str] = queue.Queue()
175170

@@ -239,7 +234,7 @@ def configure_oauth_tokens(
239234

240235
# Perform OAuth browser flow
241236
try:
242-
refresh_token, access_token = perform_oauth_browser_flow(
237+
refresh_token, access_token = do_oauth_browser_flow(
243238
login_url, client_id, client_secret, redirect_uri
244239
)
245240
except click.ClickException as e:

0 commit comments

Comments
 (0)