diff --git a/docs/my-website/docs/proxy/ui.md b/docs/my-website/docs/proxy/ui.md index d29ad865a3..1c1931f8f8 100644 --- a/docs/my-website/docs/proxy/ui.md +++ b/docs/my-website/docs/proxy/ui.md @@ -126,9 +126,15 @@ GENERIC_TOKEN_ENDPOINT = "http://localhost:9090/token" GENERIC_USERINFO_ENDPOINT = "http://localhost:9090/me" ``` -**Additional .env variables on your Proxy** +**Optional .env variables** +The following can be used to customize attribute names when interacting with the generic OAuth provider. We will read these attributes from the SSO Provider result + ```shell -GENERIC_SCOPE = "openid profile email" +GENERIC_USER_ID_ATTRIBUTE = "given_name" +GENERIC_USER_EMAIL_ATTRIBUTE = "family_name" +GENERIC_USER_ROLE_ATTRIBUTE = "given_role" + +GENERIC_SCOPE = "openid profile email" # default scope openid is sometimes not enough to retrieve basic user info like first_name and last_name located in profile scope ``` - Set Redirect URI, if your provider requires it diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index ec5c199be0..37f55072e5 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -4830,6 +4830,25 @@ async def auth_callback(request: Request): # User is Authe'd in - generate key for the UI to access Proxy user_email = getattr(result, "email", None) user_id = getattr(result, "id", None) + + # generic client id + if generic_client_id is not None: + generic_user_id_attribute_name = os.getenv("GENERIC_USER_ID_ATTRIBUTE", "email") + generic_user_email_attribute_name = os.getenv( + "GENERIC_USER_EMAIL_ATTRIBUTE", "email" + ) + generic_user_role_attribute_name = os.getenv( + "GENERIC_USER_ROLE_ATTRIBUTE", "role" + ) + + verbose_proxy_logger.debug( + f" generic_user_id_attribute_name: {generic_user_id_attribute_name}\n generic_user_email_attribute_name: {generic_user_email_attribute_name}\n generic_user_role_attribute_name: {generic_user_role_attribute_name}" + ) + + user_id = getattr(result, generic_user_id_attribute_name, None) + user_email = getattr(result, generic_user_email_attribute_name, None) + user_role = getattr(result, generic_user_role_attribute_name, None) + if user_id is None: user_id = getattr(result, "first_name", "") + getattr(result, "last_name", "") response = await generate_key_helper_fn(