pub struct OAuthClientCredentialsBuilder { /* private fields */ }Expand description
Builder for OAuthClientCredentials.
§Required Fields
client_idclient_secrettoken_endpointresource
§Example
use tower_mcp::client::OAuthClientCredentials;
let provider = OAuthClientCredentials::builder()
.client_id("my-service")
.client_secret("s3cret")
.token_endpoint("https://auth.example.com/token")
.resource("https://mcp.example.com")
.build()?;Implementations§
Source§impl OAuthClientCredentialsBuilder
impl OAuthClientCredentialsBuilder
Sourcepub fn client_secret(self, client_secret: impl Into<String>) -> Self
pub fn client_secret(self, client_secret: impl Into<String>) -> Self
Set the OAuth client secret.
Sourcepub fn token_endpoint(self, url: impl Into<String>) -> Self
pub fn token_endpoint(self, url: impl Into<String>) -> Self
Set the token endpoint URL.
Sourcepub fn token_endpoint_auth_method(
self,
method: OAuthTokenEndpointAuthMethod,
) -> Self
pub fn token_endpoint_auth_method( self, method: OAuthTokenEndpointAuthMethod, ) -> Self
Set the token endpoint authentication method.
Direct configurations default to client_secret_basic. Discovery
selects a compatible method from authorization-server metadata.
Sourcepub fn resource(self, resource: impl Into<String>) -> Self
pub fn resource(self, resource: impl Into<String>) -> Self
Set the canonical MCP protected-resource URI.
The provider includes this value as the RFC 8707 resource parameter
in every client-credentials token request.
Sourcepub fn scopes(self, scopes: impl IntoIterator<Item = impl Into<String>>) -> Self
pub fn scopes(self, scopes: impl IntoIterator<Item = impl Into<String>>) -> Self
Set the requested scopes.
Accepts an iterator of scope strings, which are joined with spaces per RFC 6749 Section 3.3.
Sourcepub fn refresh_buffer(self, duration: Duration) -> Self
pub fn refresh_buffer(self, duration: Duration) -> Self
Set the refresh buffer duration.
Tokens are refreshed this long before their actual expiry to avoid using a token that expires during a request. Default: 30 seconds.
Sourcepub fn http_client(self, client: Client) -> Self
pub fn http_client(self, client: Client) -> Self
Set a custom reqwest::Client for token requests.
Use this when you need custom TLS configuration or proxy settings.
Sourcepub fn build(self) -> Result<OAuthClientCredentials, OAuthClientError>
pub fn build(self) -> Result<OAuthClientCredentials, OAuthClientError>
Build the OAuthClientCredentials provider.
§Errors
Returns OAuthClientError::BuildError if client_id, client_secret,
token_endpoint, or resource are not set.