Skip to content

Commit d5a13a0

Browse files
committed
try to fix passkey failure
1 parent 68e12ac commit d5a13a0

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

backend/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class Config:
5959
# TOTP/Auth Config
6060
TOTP_ISSUER = os.getenv('TOTP_ISSUER', 'TopicsFlow')
6161
TOTP_VALIDITY_WINDOW = int(os.getenv('TOTP_VALIDITY_WINDOW', '1'))
62+
PASSKEY_RP_ID = os.getenv('PASSKEY_RP_ID') # Optional: Will auto-derive from FRONTEND_URL if not set
6263

6364
# External Services
6465
SMS_SERVICE_API_KEY = os.getenv('SMS_SERVICE_API_KEY')

backend/services/passkey_service.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,27 @@ def __init__(self, rp_id: str = None, rp_name: str = "TopicsFlow"):
4646
rp_name: Relying Party name (your app name)
4747
"""
4848
# Use environment variable or default
49-
self.rp_id = rp_id or os.getenv('PASSKEY_RP_ID', 'localhost')
50-
self.rp_name = rp_name or os.getenv('APP_NAME', 'TopicsFlow')
51-
5249
# Origin for WebAuthn (e.g., 'http://localhost:3000' or 'https://topicsflow.me')
5350
self.origin = os.getenv('FRONTEND_URL', 'http://localhost:3000')
5451

52+
# Determine RP ID
53+
if rp_id:
54+
self.rp_id = rp_id
55+
elif os.getenv('PASSKEY_RP_ID'):
56+
self.rp_id = os.getenv('PASSKEY_RP_ID')
57+
else:
58+
# Derive from FRONTEND_URL if not explicitly set
59+
# This handles 'https://topicsflow.me' -> 'topicsflow.me'
60+
from urllib.parse import urlparse
61+
try:
62+
parsed_url = urlparse(self.origin)
63+
self.rp_id = parsed_url.hostname or 'localhost'
64+
except Exception as e:
65+
logger.warning(f"Failed to parse FRONTEND_URL for RP ID: {e}")
66+
self.rp_id = 'localhost'
67+
68+
self.rp_name = rp_name or os.getenv('APP_NAME', 'TopicsFlow')
69+
5570
logger.info(f"PasskeyService initialized: RP ID={self.rp_id}, Origin={self.origin}")
5671

5772
def generate_registration_options(self, user_id: str, username: str, display_name: str = None) -> Dict[str, Any]:

0 commit comments

Comments
 (0)