feat(sdk): add proxy_auth for auto OAuth2/JWT token management - #20238
Merged
1 commit merged intoFeb 3, 2026
Merged
Conversation
Adds litellm.proxy_auth to automatically obtain and refresh OAuth2/JWT tokens when connecting to LiteLLM Proxy or any OAuth2-protected endpoint. - Add ProxyAuthHandler for token lifecycle (obtain, cache, refresh) - Add AzureADCredential wrapper for azure-identity credentials - Add GenericOAuth2Credential for any OAuth2 provider (Okta, Auth0, etc) - Auto-inject Authorization headers in completion() and embedding() Closes BerriAI#19834
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Greptile OverviewGreptile SummaryThis PR adds automatic OAuth2/JWT token management for authenticating with LiteLLM Proxy and other OAuth2-protected endpoints. The implementation introduces a new Key Changes:
Implementation Quality:
Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| litellm/proxy_auth/credentials.py | New credential provider module with solid OAuth2/JWT token management, proper caching, and clean protocol-based design |
| litellm/main.py | Auth injection added to completion() and embedding(), but missing from other API methods like text_completion(), transcription(), speech(), and image_generation() if they exist |
| tests/litellm/test_proxy_auth.py | Comprehensive unit tests covering all credential providers, token caching, refresh logic, and integration with litellm module |
Sequence Diagram
sequenceDiagram
participant User
participant litellm
participant ProxyAuthHandler
participant Credential
participant OAuth2Server
participant LiteLLMProxy
User->>litellm: setup proxy_auth with credential and scope
User->>litellm: completion(model, messages, ...)
litellm->>litellm: Check if proxy_auth is set
alt proxy_auth is configured
litellm->>ProxyAuthHandler: get_auth_headers()
ProxyAuthHandler->>ProxyAuthHandler: Check cached token validity
alt token missing or expires within 60s
ProxyAuthHandler->>Credential: get_token(scope)
alt AzureADCredential
Credential->>OAuth2Server: Request Azure AD token
OAuth2Server-->>Credential: Return token with expiration
else GenericOAuth2Credential
Credential->>OAuth2Server: POST client credentials grant
OAuth2Server-->>Credential: Return token with expiration
end
Credential-->>ProxyAuthHandler: AccessToken object
ProxyAuthHandler->>ProxyAuthHandler: Cache token
end
ProxyAuthHandler-->>litellm: Authorization headers dict
litellm->>litellm: Update request headers
end
litellm->>LiteLLMProxy: HTTP Request with Authorization
LiteLLMProxy-->>litellm: Response
litellm-->>User: ModelResponse
ghost
merged commit Feb 3, 2026
b33e1e8
into
BerriAI:litellm_oss_staging_02_03_2026
6 of 8 checks passed
|
Hi @Chesars can you document this please? |
3 tasks
Contributor
Author
fzowl
pushed a commit
to fzowl/litellm
that referenced
this pull request
Jun 24, 2026
…AI#20238) Adds litellm.proxy_auth to automatically obtain and refresh OAuth2/JWT tokens when connecting to LiteLLM Proxy or any OAuth2-protected endpoint. - Add ProxyAuthHandler for token lifecycle (obtain, cache, refresh) - Add AzureADCredential wrapper for azure-identity credentials - Add GenericOAuth2Credential for any OAuth2 provider (Okta, Auth0, etc) - Auto-inject Authorization headers in completion() and embedding() Closes BerriAI#19834
This pull request was closed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Relevant issues
Fixes #19834
Pre-Submission checklist
tests/litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unitType
🆕 New Feature
Changes
Adds
litellm.proxy_authto automatically obtain and refresh OAuth2/JWT tokens when connecting to LiteLLM Proxy or any OAuth2-protected endpoint.Features:
Usage:
Tests:
poetry run pytest tests/litellm/test_proxy_auth.py -v