(chore) cleanup proxy server

This commit is contained in:
ishaan-jaff 2024-01-30 15:20:40 -08:00
parent 49a16662bf
commit 7ecfb5c368

View file

@ -3055,102 +3055,6 @@ async def auth_callback(request: Request):
return RedirectResponse(url=litellm_dashboard_ui)
# @app.get("/google-callback", tags=["experimental"], response_model=GenerateKeyResponse)
# async def google_callback(code: str, request: Request):
# import httpx
# GOOGLE_REDIRECT_URI = os.getenv("PROXY_BASE_URL")
# if GOOGLE_REDIRECT_URI is None:
# raise ProxyException(
# message="PROXY_BASE_URL not set. Set it in .env file",
# type="auth_error",
# param="PROXY_BASE_URL",
# code=status.HTTP_500_INTERNAL_SERVER_ERROR,
# )
# # Add "/google-callback"" to your callback URL
# if GOOGLE_REDIRECT_URI.endswith("/"):
# GOOGLE_REDIRECT_URI += "google-callback"
# else:
# GOOGLE_REDIRECT_URI += "/google-callback"
# GOOGLE_CLIENT_ID = os.getenv("GOOGLE_CLIENT_ID")
# if GOOGLE_CLIENT_ID is None:
# GOOGLE_CLIENT_ID = (
# "246483686424-clje5sggkjma26ilktj6qssakqhoon0m.apps.googleusercontent.com"
# )
# GOOGLE_CLIENT_SECRET = os.getenv("GOOGLE_CLIENT_SECRET")
# if GOOGLE_CLIENT_SECRET is None:
# GOOGLE_CLIENT_SECRET = "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"
# verbose_proxy_logger.info(
# f"/google-callback\n GOOGLE_REDIRECT_URI: {GOOGLE_REDIRECT_URI}\n GOOGLE_CLIENT_ID: {GOOGLE_CLIENT_ID}"
# )
# # Exchange code for access token
# async with httpx.AsyncClient() as client:
# token_url = f"https://oauth2.googleapis.com/token"
# data = {
# "code": code,
# "client_id": GOOGLE_CLIENT_ID,
# "client_secret": GOOGLE_CLIENT_SECRET,
# "redirect_uri": GOOGLE_REDIRECT_URI,
# "grant_type": "authorization_code",
# }
# response = await client.post(token_url, data=data)
# # Process the response, extract user info, etc.
# if response.status_code == 200:
# access_token = response.json()["access_token"]
# # Fetch user info using the access token
# async with httpx.AsyncClient() as client:
# user_info_url = "https://www.googleapis.com/oauth2/v1/userinfo"
# headers = {"Authorization": f"Bearer {access_token}"}
# user_info_response = await client.get(user_info_url, headers=headers)
# # Process user info response
# if user_info_response.status_code == 200:
# user_info = user_info_response.json()
# user_email = user_info.get("email")
# user_name = user_info.get("name")
# # we can use user_email on litellm proxy now
# # TODO: Handle user info as needed, for example, store it in a database, authenticate the user, etc.
# response = await generate_key_helper_fn(
# **{"duration": "24hr", "models": [], "aliases": {}, "config": {}, "spend": 0, "user_id": user_email, "team_id": "litellm-dashboard"} # type: ignore
# )
# key = response["token"] # type: ignore
# user_id = response["user_id"] # type: ignore
# litellm_dashboard_ui = "https://litellm-dashboard.vercel.app/"
# # if user set LITELLM_UI_LINK in .env, use that
# litellm_ui_link_in_env = os.getenv("LITELLM_UI_LINK", None)
# if litellm_ui_link_in_env is not None:
# litellm_dashboard_ui = litellm_ui_link_in_env
# litellm_dashboard_ui += (
# "?userID="
# + user_id
# + "&accessToken="
# + key
# + "&proxyBaseUrl="
# + os.getenv("PROXY_BASE_URL")
# )
# return RedirectResponse(url=litellm_dashboard_ui)
# else:
# # Handle user info retrieval error
# raise HTTPException(
# status_code=user_info_response.status_code,
# detail=user_info_response.text,
# )
# else:
# # Handle the error from the token exchange
# raise HTTPException(status_code=response.status_code, detail=response.text)
@router.get(
"/user/info", tags=["user management"], dependencies=[Depends(user_api_key_auth)]
)