refactor: extract OAuth helper functions and simplify provider state (#1586)

This commit is contained in:
Max Isbey 2025-11-13 13:28:48 +00:00 • committed by GitHub
commit 7d12e83cf4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,5 +1,6 @@
"""Utilities for OAuth 2.0 Resource Indicators (RFC 8707)."""
"""Utilities for OAuth 2.0 Resource Indicators (RFC 8707) and PKCE (RFC 7636)."""
import time
from urllib.parse import urlparse, urlsplit, urlunsplit
from pydantic import AnyUrl, HttpUrl
@ -67,3 +68,18 @@ def check_resource_allowed(requested_resource: str, configured_resource: str) ->
configured_path += "/"
return requested_path.startswith(configured_path)
def calculate_token_expiry(expires_in: int | str | None) -> float | None:
"""Calculate token expiry timestamp from expires_in seconds.
Args:
expires_in: Seconds until token expiration (may be string from some servers)
Returns:
Unix timestamp when token expires, or None if no expiry specified
"""
if expires_in is None:
return None # pragma: no cover
# Defensive: handle servers that return expires_in as string
return time.time() + int(expires_in)