pub struct IntrospectionClient { /* private fields */ }Expand description
Token introspection client
§Example
use turbomcp_auth::introspection::IntrospectionClient;
let client = IntrospectionClient::new(
"https://auth.example.com/oauth/introspect".to_string(),
"my_client_id".to_string(),
Some("my_client_secret".to_string()),
);
// Full introspection
let response = client.introspect("token_here", Some("access_token")).await?;
println!("Token active: {}", response.active);
println!("Token scopes: {:?}", response.scope);
// Quick check
let is_active = client.is_token_active("token_here").await?;Implementations§
Source§impl IntrospectionClient
impl IntrospectionClient
Sourcepub fn new(
endpoint: String,
client_id: String,
client_secret: Option<String>,
) -> Self
pub fn new( endpoint: String, client_id: String, client_secret: Option<String>, ) -> Self
Create a new introspection client
§Arguments
endpoint- Token introspection endpoint URLclient_id- Client ID for authenticating with the introspection endpointclient_secret- Client secret (None for public clients)
§Example
use turbomcp_auth::introspection::IntrospectionClient;
// Confidential client
let client = IntrospectionClient::new(
"https://auth.example.com/introspect".to_string(),
"client_id".to_string(),
Some("secret".to_string()),
);
// Public client
let public_client = IntrospectionClient::new(
"https://auth.example.com/introspect".to_string(),
"public_client".to_string(),
None,
);Sourcepub async fn introspect(
&self,
token: &str,
token_type_hint: Option<&str>,
) -> McpResult<IntrospectionResponse>
pub async fn introspect( &self, token: &str, token_type_hint: Option<&str>, ) -> McpResult<IntrospectionResponse>
Introspect a token per RFC 7662
§Arguments
token- The token to introspecttoken_type_hint- Optional hint (e.g., “access_token”, “refresh_token”)
§Returns
IntrospectionResponse indicating if token is active and its metadata
§Errors
Returns error if:
- HTTP request fails
- Response is malformed
- Authentication fails
§Example
let response = client.introspect("my_token", Some("access_token")).await?;
if response.active {
println!("Token is valid");
println!("Subject: {:?}", response.sub);
println!("Scopes: {:?}", response.scope);
} else {
println!("Token is revoked or expired");
}Sourcepub async fn is_token_active(&self, token: &str) -> McpResult<bool>
pub async fn is_token_active(&self, token: &str) -> McpResult<bool>
Check if a token is active (convenience method)
This is a shortcut for introspect() that only returns the active field.
§Example
if client.is_token_active("my_token").await? {
// Token is valid, proceed
} else {
// Token is revoked or expired, reject
}Trait Implementations§
Source§impl Clone for IntrospectionClient
impl Clone for IntrospectionClient
Source§fn clone(&self) -> IntrospectionClient
fn clone(&self) -> IntrospectionClient
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for IntrospectionClient
impl !RefUnwindSafe for IntrospectionClient
impl Send for IntrospectionClient
impl Sync for IntrospectionClient
impl Unpin for IntrospectionClient
impl !UnwindSafe for IntrospectionClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more