feat: add client credentials token support for M2M - #138
Open
kishore7snehil wants to merge 2 commits into
Open
kishore7snehil wants to merge 2 commits into
kishore7snehil wants to merge 2 commits into
Conversation
Add an ApiClient method to obtain a client credentials (M2M) access token for server-to-server calls using the OAuth 2.0 client credentials grant. The method authenticates via HTTP Basic and caches the result in a configured token_store keyed by audience and scope set, so a repeat call within the token's lifetime skips the network round-trip. Add the ClientCredentialsTokenResult type and GetClientCredentialsTokenError, and document the method in the README and examples. Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
kishore7snehil
marked this pull request as ready for review
October 6, 2026 06:50
This branch has not been deployed
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.
📋 Changes
This PR adds
get_client_credentials_token()toApiClientfor obtaining machine-to-machine access tokens with the OAuth 2.0 client credentials grant. When a token store is configured, the result is cached so repeat calls within the token's lifetime skip the network round-trip.✨ Features
get_client_credentials_token(audience, scope=None)method that authenticates with HTTP Basic using the configuredclient_idandclient_secret.token_storeis set, tokens are cached per tenant, client, audience, and scope set. Store read and write failures are logged and fall back to a fresh exchange.ClientCredentialsTokenResultTypedDict.🔧 API Changes
ApiClient.get_client_credentials_token()ClientCredentialsTokenResult(TypedDict)GetClientCredentialsTokenError, raised when client credentials are not configured or the token endpoint is missing from discovery metadata📖 Documentation
README.mdwith a client credentials sectionEXAMPLES.mdwith a client credentials example🧪 Testing
Contributor Checklist
🤖 Generated with Claude Code