From f1b1640a31a7c43316f5ccabb3d96637fa9d6d91 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Mon, 25 Mar 2024 12:30:40 -0700 Subject: [PATCH] fix(handle_jwt.py): support scopes being a list allow scopes in jwt to be a list, not just a space-separated string --- litellm/proxy/auth/handle_jwt.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/litellm/proxy/auth/handle_jwt.py b/litellm/proxy/auth/handle_jwt.py index 2561088e9..898fca8ce 100644 --- a/litellm/proxy/auth/handle_jwt.py +++ b/litellm/proxy/auth/handle_jwt.py @@ -134,8 +134,15 @@ class JWTHandler: def get_scopes(self, token: dict) -> list: try: - # Assuming the scopes are stored in 'scope' claim and are space-separated - scopes = token["scope"].split() + if isinstance(token["scope"], str): + # Assuming the scopes are stored in 'scope' claim and are space-separated + 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: scopes = [] return scopes