@@ -2,11 +2,12 @@ mod models;
22
33use crate :: { Method , QueryArgs , QueryResult , Sdk , SdkResult , NO_BODY } ;
44use anyhow:: { format_err, Result } ;
5- use jsonwebtoken:: {
6- DecodingKey , TokenData , Validation ,
7- } ;
5+ use jsonwebtoken:: { DecodingKey , TokenData , Validation } ;
86pub use models:: * ;
9- pub use oauth2:: { basic:: { BasicTokenIntrospectionResponse , BasicTokenType } , TokenIntrospectionResponse , TokenResponse } ;
7+ pub use oauth2:: {
8+ basic:: { BasicTokenIntrospectionResponse , BasicTokenType } ,
9+ TokenIntrospectionResponse , TokenResponse ,
10+ } ;
1011use oauth2:: { url, AccessToken , AuthUrl , AuthorizationCode , ClientId , ClientSecret , IntrospectionUrl , RedirectUrl , RefreshToken , TokenUrl } ;
1112use openssl:: pkey:: Id ;
1213use openssl:: {
@@ -132,9 +133,14 @@ impl AuthSdk {
132133
133134 let pb_key = self . sdk . replace_cert_to_pub_key ( ) . unwrap ( ) ;
134135
135- let td = get_tk ( pb_key, validation, token) . unwrap ( ) ;
136-
137- Ok ( td. claims )
136+ match get_tk ( pb_key, validation, token) {
137+ Ok ( td) => {
138+ return Ok ( td. claims ) ;
139+ }
140+ Err ( e) => {
141+ return Err ( e. downcast ( ) . unwrap ( ) ) ;
142+ }
143+ }
138144 }
139145
140146 pub fn get_signing_url ( & self , redirect_url : String ) -> String {
@@ -251,24 +257,22 @@ fn get_tk(pb_key: PKey<Public>, validation: Validation, token: &str) -> Result<T
251257 let token_data: TokenData < ClaimsStandard > = jsonwebtoken:: decode ( token, decode_key, & validation) ?;
252258
253259 Ok ( token_data)
254- } ,
260+ }
255261 Id :: EC => {
256262 let ec_pb_key = pb_key. ec_key ( ) ?. public_key_to_pem ( ) ?;
257263 let decode_key = & DecodingKey :: from_ec_pem ( & ec_pb_key) ?;
258264 let token_data: TokenData < ClaimsStandard > = jsonwebtoken:: decode ( token, decode_key, & validation) ?;
259265
260266 Ok ( token_data)
261- } ,
267+ }
262268 Id :: RSA_PSS => {
263269 let ec_pb_key = pb_key. rsa ( ) ?. public_key_to_pem ( ) ?;
264270 let decode_key = & DecodingKey :: from_rsa_pem ( & ec_pb_key) ?;
265271 let token_data: TokenData < ClaimsStandard > = jsonwebtoken:: decode ( token, decode_key, & validation) ?;
266272
267273 Ok ( token_data)
268- } ,
269- _ => {
270- Err ( format_err ! ( "not supported" ) )
271- } ,
274+ }
275+ _ => Err ( format_err ! ( "not supported" ) ) ,
272276 }
273277}
274278
@@ -288,9 +292,9 @@ mod tests {
288292 "7d315de093a1b8268d0c7eb192bbe02f35a8877d" . to_string ( ) ,
289293 cert,
290294 "built-in" . to_string ( ) ,
291- Some ( "app-built-in" . to_owned ( ) )
295+ Some ( "app-built-in" . to_owned ( ) ) ,
292296 )
293- . into_sdk ( ) ;
297+ . into_sdk ( ) ;
294298
295299 let authnx = cfg. authn ( ) ;
296300
@@ -308,9 +312,9 @@ mod tests {
308312 "secret" . to_string ( ) ,
309313 cert,
310314 "Kubernetes" . to_string ( ) ,
311- Some ( "Cluster" . to_owned ( ) )
315+ Some ( "Cluster" . to_owned ( ) ) ,
312316 )
313- . into_sdk ( ) ;
317+ . into_sdk ( ) ;
314318
315319 let authnx = cfg. authn ( ) ;
316320
@@ -327,9 +331,9 @@ mod tests {
327331 "secret" . to_string ( ) ,
328332 cert,
329333 "Kubernetes" . to_string ( ) ,
330- Some ( "Cluster" . to_owned ( ) )
334+ Some ( "Cluster" . to_owned ( ) ) ,
331335 )
332- . into_sdk ( ) ;
336+ . into_sdk ( ) ;
333337
334338 let authnx = cfg. authn ( ) ;
335339
@@ -348,7 +352,7 @@ mod tests {
348352 "secret" . to_string ( ) ,
349353 cert,
350354 "org_name" . to_string ( ) ,
351- Some ( "app_name" . to_owned ( ) )
355+ Some ( "app_name" . to_owned ( ) ) ,
352356 )
353357 . into_sdk ( ) ;
354358
@@ -369,7 +373,7 @@ mod tests {
369373 "secret" . to_string ( ) ,
370374 cert,
371375 "org_name" . to_string ( ) ,
372- Some ( "app_name" . to_owned ( ) )
376+ Some ( "app_name" . to_owned ( ) ) ,
373377 )
374378 . into_sdk ( ) ;
375379
@@ -390,7 +394,7 @@ mod tests {
390394 "secret" . to_string ( ) ,
391395 cert,
392396 "org_name" . to_string ( ) ,
393- Some ( "app_name" . to_owned ( ) )
397+ Some ( "app_name" . to_owned ( ) ) ,
394398 )
395399 . into_sdk ( ) ;
396400
@@ -412,7 +416,7 @@ mod tests {
412416 "secret" . to_string ( ) ,
413417 cert,
414418 "org_name" . to_string ( ) ,
415- Some ( "app_name" . to_owned ( ) )
419+ Some ( "app_name" . to_owned ( ) ) ,
416420 )
417421 . into_sdk ( ) ;
418422
@@ -432,7 +436,7 @@ mod tests {
432436 "secret" . to_string ( ) ,
433437 cert,
434438 "org_name" . to_string ( ) ,
435- Some ( "app_name" . to_owned ( ) )
439+ Some ( "app_name" . to_owned ( ) ) ,
436440 )
437441 . into_sdk ( ) ;
438442
0 commit comments