mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 10:44:24 +00:00
* ci(config.yml): add a 'check_code_quality' step Addresses https://github.com/BerriAI/litellm/issues/5991 * ci(config.yml): check why circle ci doesn't pick up this test * ci(config.yml): fix to run 'check_code_quality' tests * fix(__init__.py): fix unprotected import * fix(__init__.py): don't remove unused imports * build(ruff.toml): update ruff.toml to ignore unused imports * fix: fix: ruff + pyright - fix linting + type-checking errors * fix: fix linting errors * fix(lago.py): fix module init error * fix: fix linting errors * ci(config.yml): cd into correct dir for checks * fix(proxy_server.py): fix linting error * fix(utils.py): fix bare except causes ruff linting errors * fix: ruff - fix remaining linting errors * fix(clickhouse.py): use standard logging object * fix(__init__.py): fix unprotected import * fix: ruff - fix linting errors * fix: fix linting errors * ci(config.yml): cleanup code qa step (formatting handled in local_testing) * fix(_health_endpoints.py): fix ruff linting errors * ci(config.yml): just use ruff in check_code_quality pipeline for now * build(custom_guardrail.py): include missing file * style(embedding_handler.py): fix ruff check
49 lines
1.6 KiB
Python
49 lines
1.6 KiB
Python
"""
|
|
Example Custom SSO Handler
|
|
|
|
Use this if you want to run custom code after litellm has retrieved information from your IDP (Identity Provider).
|
|
|
|
Flow:
|
|
- User lands on Admin UI
|
|
- LiteLLM redirects user to your SSO provider
|
|
- Your SSO provider redirects user back to LiteLLM
|
|
- LiteLLM has retrieved user information from your IDP
|
|
- Your custom SSO handler is called and returns an object of type SSOUserDefinedValues
|
|
- User signed in to UI
|
|
"""
|
|
|
|
from fastapi import Request
|
|
from fastapi_sso.sso.base import OpenID
|
|
|
|
from litellm.proxy._types import LitellmUserRoles, SSOUserDefinedValues
|
|
from litellm.proxy.management_endpoints.internal_user_endpoints import (
|
|
new_user,
|
|
user_info,
|
|
)
|
|
from litellm.proxy.management_endpoints.team_endpoints import add_new_member
|
|
|
|
|
|
async def custom_sso_handler(userIDPInfo: OpenID) -> SSOUserDefinedValues:
|
|
try:
|
|
print("inside custom sso handler") # noqa
|
|
print(f"userIDPInfo: {userIDPInfo}") # noqa
|
|
|
|
if userIDPInfo.id is None:
|
|
raise ValueError(
|
|
f"No ID found for user. userIDPInfo.id is None {userIDPInfo}"
|
|
)
|
|
|
|
# check if user exists in litellm proxy DB
|
|
_user_info = await user_info(user_id=userIDPInfo.id)
|
|
print("_user_info from litellm DB ", _user_info) # noqa
|
|
|
|
return SSOUserDefinedValues(
|
|
models=[],
|
|
user_id=userIDPInfo.id,
|
|
user_email=userIDPInfo.email,
|
|
user_role=LitellmUserRoles.INTERNAL_USER.value,
|
|
max_budget=10,
|
|
budget_duration="1d",
|
|
)
|
|
except Exception:
|
|
raise Exception("Failed custom auth")
|