- Added Codex authentication endpoints and logic for OAuth flow. - Updated Docker configuration to expose port 1455 for Codex callback. - Enhanced user configuration model to include Codex-related fields. - Integrated Codex selection into the LLM provider UI. - Implemented token management and refresh logic for Codex. - Added utility functions for handling Codex OAuth tokens and state management.
23 lines
652 B
Python
23 lines
652 B
Python
"""
|
|
PKCE utilities using Python's secrets and hashlib.
|
|
Python port of pi-mono-main/packages/ai/src/utils/oauth/pkce.ts
|
|
"""
|
|
import base64
|
|
import hashlib
|
|
import secrets
|
|
|
|
|
|
def generate_pkce() -> tuple[str, str]:
|
|
"""
|
|
Generate PKCE code verifier and challenge (S256 method).
|
|
|
|
Returns:
|
|
(verifier, challenge) — both base64url-encoded, no padding
|
|
"""
|
|
verifier_bytes = secrets.token_bytes(32)
|
|
verifier = base64.urlsafe_b64encode(verifier_bytes).rstrip(b"=").decode()
|
|
|
|
digest = hashlib.sha256(verifier.encode()).digest()
|
|
challenge = base64.urlsafe_b64encode(digest).rstrip(b"=").decode()
|
|
|
|
return verifier, challenge
|