fix(handle_jwt.py): support scopes being a list

allow scopes in jwt to be a list, not just a space-separated string
This commit is contained in:
Krrish Dholakia 2024-03-25 12:30:40 -07:00
parent 5aa1c10929
commit f1b1640a31

View file

@ -134,8 +134,15 @@ class JWTHandler:
def get_scopes(self, token: dict) -> list: def get_scopes(self, token: dict) -> list:
try: try:
if isinstance(token["scope"], str):
# Assuming the scopes are stored in 'scope' claim and are space-separated # Assuming the scopes are stored in 'scope' claim and are space-separated
scopes = token["scope"].split() scopes = token["scope"].split()
elif isinstance(token["scope"], list):
scopes = token["scope"]
else:
raise Exception(
f"Unmapped scope type - {type(token['scope'])}. Supported types - list, str."
)
except KeyError: except KeyError:
scopes = [] scopes = []
return scopes return scopes