From 2abd4d5363dcb2e6086c3eeea39d32a3ec6421ec Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Tue, 6 Aug 2024 12:53:03 -0700 Subject: [PATCH] feat(proxy_server.py): allow restricting allowed email domains for the UI --- litellm/proxy/proxy_server.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index db7fa3a568..47c17d49de 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -8557,6 +8557,19 @@ async def auth_callback(request: Request): user_email = getattr(result, "email", None) user_id = getattr(result, "id", None) + if user_email is not None and os.getenv("ALLOWED_EMAIL_DOMAINS") is not None: + email_domain = user_email.split("@")[1] + allowed_domains = os.getenv("ALLOWED_EMAIL_DOMAINS").split(",") # type: ignore + if email_domain not in allowed_domains: + raise HTTPException( + status_code=401, + detail={ + "message": "The email domain={}, is not an allowed email domain={}. Contact your admin to change this.".format( + email_domain, allowed_domains + ) + }, + ) + # generic client id if generic_client_id is not None: user_id = getattr(result, "id", None)