1
1
use anyhow:: { Context , Error } ;
2
2
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
7
4
} ;
8
5
use reqwest:: Url ;
9
6
@@ -32,7 +29,7 @@ impl OAuthClient {
32
29
let token_endpoint =
33
30
TokenUrl :: new ( config. token_endpoint . clone ( ) ) . context ( "Failed to parse token url" ) ?;
34
31
35
- let client = BasicClient :: new (
32
+ let mut client = BasicClient :: new (
36
33
ClientId :: new ( config. client_id . clone ( ) ) ,
37
34
Some ( ClientSecret :: new ( config. client_secret . clone ( ) ) ) ,
38
35
auth_url,
@@ -41,6 +38,12 @@ impl OAuthClient {
41
38
. set_auth_type ( AuthType :: RequestBody )
42
39
. set_redirect_uri ( redirect_uri) ;
43
40
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
+
44
47
Ok ( Self { config, client } )
45
48
}
46
49
@@ -87,4 +90,19 @@ impl OAuthClient {
87
90
88
91
Ok ( response. unwrap ( ) )
89
92
}
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
+ }
90
108
}
0 commit comments