Skip to content

Commit fc0c516

Browse files
feat: add token introspection
1 parent 63c6165 commit fc0c516

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

baffao-core/src/oauth/client.rs

+23-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use anyhow::{Context, Error};
22
use oauth2::{
3-
basic::{BasicClient, BasicTokenType},
4-
reqwest::async_http_client,
5-
AuthType, AuthUrl, AuthorizationCode, ClientId, ClientSecret, CsrfToken, EmptyExtraTokenFields,
6-
PkceCodeChallenge, PkceCodeVerifier, RedirectUrl, Scope, StandardTokenResponse, TokenUrl,
3+
basic::{BasicClient, BasicTokenType}, reqwest::async_http_client, AccessToken, AuthType, AuthUrl, AuthorizationCode, ClientId, ClientSecret, CsrfToken, EmptyExtraTokenFields, IntrospectionUrl, PkceCodeChallenge, PkceCodeVerifier, RedirectUrl, Scope, StandardTokenIntrospectionResponse, StandardTokenResponse, TokenUrl
74
};
85
use reqwest::Url;
96

@@ -32,7 +29,7 @@ impl OAuthClient {
3229
let token_endpoint =
3330
TokenUrl::new(config.token_endpoint.clone()).context("Failed to parse token url")?;
3431

35-
let client = BasicClient::new(
32+
let mut client = BasicClient::new(
3633
ClientId::new(config.client_id.clone()),
3734
Some(ClientSecret::new(config.client_secret.clone())),
3835
auth_url,
@@ -41,6 +38,12 @@ impl OAuthClient {
4138
.set_auth_type(AuthType::RequestBody)
4239
.set_redirect_uri(redirect_uri);
4340

41+
if let Some(introspection_endpoint) = &config.introspection_endpoint {
42+
let introspection_endpoint = IntrospectionUrl::new(introspection_endpoint.clone())
43+
.context("Failed to parse introspection url")?;
44+
client = client.set_introspection_uri(introspection_endpoint);
45+
}
46+
4447
Ok(Self { config, client })
4548
}
4649

@@ -87,4 +90,19 @@ impl OAuthClient {
8790

8891
Ok(response.unwrap())
8992
}
93+
94+
pub async fn introspect_token(
95+
&self,
96+
token: String,
97+
) -> Result<StandardTokenIntrospectionResponse<EmptyExtraTokenFields, BasicTokenType>, Error> {
98+
let response = self
99+
.client
100+
.introspect(&AccessToken::new(token))?
101+
.request_async(async_http_client)
102+
.await?;
103+
104+
// TODO: configure introspection request depending on auth method
105+
106+
Ok(response)
107+
}
90108
}

baffao-core/src/oauth/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@ pub struct OAuthConfig {
1919
pub token_endpoint: String,
2020
pub redirect_uri: Option<String>,
2121
pub default_scopes: Option<Vec<String>>,
22+
23+
pub introspection_endpoint: Option<String>,
24+
pub introspection_endpoint_auth_methods_supported: Option<Vec<String>>,
25+
pub introspection_endpoint_auth_signing_alg_values_supported: Option<Vec<String>>,
2226
}

0 commit comments

Comments
 (0)