Introduce client credentials flow support #972
Draft
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.
The PR adds
authFlowa new optional method to theOAuthClientProviderinterface.The authFlow method will be used by the
authInternalto select the appropriate flow to be executed. In case that the provider does not implement the new method the default value will beauthorization_code.When
client/auth.ts::authInternalreturnsclient_credentialsa call to /token endpoint will be made withclient_credentialsgrant type.This should resolve #899
Motivation and Context
Enhancing the OAuthClientProvider class to support the client_credentials OAuth flow will allow the MCP machine client to retrieve tokens from the authorization server. This is necessary for machine-to-machine authentication scenarios where no user context is available.
How Has This Been Tested?
I wrote some unit tests, trying to follow the code style already present in the codebase.
I also manually update, but not commited, the
simpleOAuthClient.tsto perform a client_crendential flow using WorkOs as AuthorizationServerBreaking Changes
The PR should not bring breaking changes,
authInternalmethod by default will use the old "authorization_flow" flow.Types of changes
Checklist
Additional context