blob: 313a6671d4dae8f890c0b4e71f3d53866e5b412e (
about) (
plain)
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
|
import base64
import json
def get_tenant_id_from_jwt(token: str) -> str:
claims = extract_claims_from_jwt(token)
return claims.get("sub")
def get_addresses_from_jwt(token: str) -> (str, str):
claims = extract_claims_from_jwt(token)
return claims.get("server_url"), claims.get("grpc_broadcast_address")
def extract_claims_from_jwt(token: str):
parts = token.split(".")
if len(parts) != 3:
raise ValueError("Invalid token format")
claims_part = parts[1]
claims_part += "=" * ((4 - len(claims_part) % 4) % 4) # Padding for base64 decoding
claims_data = base64.urlsafe_b64decode(claims_part)
claims = json.loads(claims_data)
return claims
|