mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 11:14:04 +00:00
(Feat) - LiteLLM Use UsernamePasswordCredential
for Azure OpenAI (#7496)
* add get_azure_ad_token_from_username_password * docs azure use username / password for auth * update doc * get_azure_ad_token_from_username_password * test test_get_azure_ad_token_from_username_password
This commit is contained in:
parent
0b4d529af8
commit
0cbecbe185
6 changed files with 131 additions and 8 deletions
|
@ -137,3 +137,44 @@ def get_azure_ad_token_from_entrata_id(
|
|||
verbose_logger.debug("token_provider %s", token_provider)
|
||||
|
||||
return token_provider
|
||||
|
||||
|
||||
def get_azure_ad_token_from_username_password(
|
||||
client_id: str,
|
||||
azure_username: str,
|
||||
azure_password: str,
|
||||
scope: str = "https://cognitiveservices.azure.com/.default",
|
||||
) -> Callable[[], str]:
|
||||
"""
|
||||
Get Azure AD token provider from `client_id`, `azure_username`, and `azure_password`
|
||||
|
||||
Args:
|
||||
client_id: str
|
||||
azure_username: str
|
||||
azure_password: str
|
||||
scope: str
|
||||
|
||||
Returns:
|
||||
callable that returns a bearer token.
|
||||
"""
|
||||
from azure.identity import UsernamePasswordCredential, get_bearer_token_provider
|
||||
|
||||
verbose_logger.debug(
|
||||
"client_id %s, azure_username %s, azure_password %s",
|
||||
client_id,
|
||||
azure_username,
|
||||
azure_password,
|
||||
)
|
||||
credential = UsernamePasswordCredential(
|
||||
client_id=client_id,
|
||||
username=azure_username,
|
||||
password=azure_password,
|
||||
)
|
||||
|
||||
verbose_logger.debug("credential %s", credential)
|
||||
|
||||
token_provider = get_bearer_token_provider(credential, scope)
|
||||
|
||||
verbose_logger.debug("token_provider %s", token_provider)
|
||||
|
||||
return token_provider
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue