forked from databricks/databricks-sql-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauth_utils.py
More file actions
47 lines (38 loc) · 1.26 KB
/
auth_utils.py
File metadata and controls
47 lines (38 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import logging
import jwt
from datetime import datetime, timedelta
from typing import Optional, Dict, Tuple
from urllib.parse import urlparse
logger = logging.getLogger(__name__)
def decode_token(access_token: str) -> Optional[Dict]:
"""
Decode a JWT token without verification to extract claims.
Args:
access_token: The JWT access token to decode
Returns:
Decoded token claims or None if decoding fails
"""
try:
return jwt.decode(access_token, options={"verify_signature": False})
except Exception as e:
logger.debug("Failed to decode JWT token: %s", e)
return None
def is_same_host(url1: str, url2: str) -> bool:
"""
Check if two URLs have the same host.
Args:
url1: First URL
url2: Second URL
Returns:
True if hosts are the same, False otherwise
"""
try:
host1 = urlparse(url1).netloc
host2 = urlparse(url2).netloc
# Handle port differences (e.g., example.com vs example.com:443)
host1_without_port = host1.split(":")[0]
host2_without_port = host2.split(":")[0]
return host1_without_port == host2_without_port
except Exception as e:
logger.debug("Failed to parse URLs: %s", e)
return False