mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-12 03:48:56 +00:00
refactor(types): move is_jwt into litellm.types.proxy.auth.user_api_key_auth (#45747)
* refactor(types): move LitellmUserRoles and KeyManagementRoutes into litellm.types.proxy.auth.user_roles Part of LIT-9423 * refactor(types): move is_jwt into litellm.types.proxy.auth.user_api_key_auth Part of LIT-9423 * refactor(auth): alias is_jwt import so JWTHandler.is_jwt is not read as recursive
This commit is contained in:
parent
a859d844ed
commit
7831d8a991
3 changed files with 12 additions and 7 deletions
|
|
@ -67,6 +67,7 @@ from litellm.types.proxy.agent_identity import ManagedAgentContext
|
|||
from litellm.types.proxy.auth.special_headers import (
|
||||
SpecialHeaders as SpecialHeaders, # noqa: PLC0414 # public re-export
|
||||
)
|
||||
from litellm.types.proxy.auth.user_api_key_auth import is_jwt
|
||||
from litellm.types.proxy.carried_budget_state import (
|
||||
OrgBudgetSnapshot,
|
||||
TeamBudgetSnapshot,
|
||||
|
|
@ -3482,9 +3483,7 @@ class UserAPIKeyAuth(LiteLLM_VerificationTokenView): # the expected response ob
|
|||
normalized = normalized[7:]
|
||||
if normalized.startswith("sk-"):
|
||||
return hash_token(normalized)
|
||||
from litellm.proxy.auth.handle_jwt import JWTHandler
|
||||
|
||||
if JWTHandler.is_jwt(token=normalized):
|
||||
if is_jwt(token=normalized):
|
||||
return f"hashed-jwt-{hash_token(token=normalized)}"
|
||||
return normalized
|
||||
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ from litellm.repositories.user_repository import UserRepository
|
|||
from litellm.types.agents import AgentResponse
|
||||
from litellm.types.proxy.agent_identity import AgentIdentityFailure
|
||||
from litellm.types.proxy.auth.auth_checks import UserNotFoundError
|
||||
from litellm.types.proxy.auth.user_api_key_auth import is_jwt as is_jwt_token
|
||||
|
||||
from .auth_checks import (
|
||||
TeamNotFoundError,
|
||||
|
|
@ -276,10 +277,7 @@ class JWTHandler:
|
|||
|
||||
@staticmethod
|
||||
def is_jwt(token: str | None) -> bool:
|
||||
if token is None:
|
||||
return False
|
||||
parts: Final = token.split(".")
|
||||
return len(parts) == 3
|
||||
return is_jwt_token(token=token)
|
||||
|
||||
@staticmethod
|
||||
def get_unverified_claims(token: str) -> dict | None:
|
||||
|
|
|
|||
8
litellm/types/proxy/auth/user_api_key_auth.py
Normal file
8
litellm/types/proxy/auth/user_api_key_auth.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from typing import Final
|
||||
|
||||
|
||||
def is_jwt(token: str | None) -> bool:
|
||||
if token is None:
|
||||
return False
|
||||
parts: Final = token.split(".")
|
||||
return len(parts) == 3
|
||||
Loading…
Add table
Reference in a new issue