mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-05 20:23:18 +00:00
Merge pull request #2021 from BerriAI/litellm_fix_generic_sso
[FEAT] Generic SSO - allow user to specify attribute names
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user