-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathutils.py
30 lines (23 loc) · 907 Bytes
/
utils.py
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
from typing import Any, Dict
import jwt
def is_guest(claims: Dict[str, Any]) -> bool:
"""
Check if the user is a guest user
"""
# if the user has set up `acct` claim in Azure, that's most efficient. 0 = tenant member, 1 = guest
if claims.get('acct') == 1:
return True
# formula: idp exist and idp != iss: guest user
claims_iss: str = claims.get('iss', '')
idp: str = claims.get('idp', claims_iss)
return idp != claims_iss
def get_unverified_header(access_token: str) -> Dict[str, Any]:
"""
Get header from the access token without verifying the signature
"""
return dict(jwt.get_unverified_header(access_token))
def get_unverified_claims(access_token: str) -> Dict[str, Any]:
"""
Get claims from the access token without verifying the signature
"""
return dict(jwt.decode(access_token, options={'verify_signature': False}))