File tree Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Original file line number Diff line number Diff line change 22use  std:: collections:: HashMap ; 
33
44use  jsonwebtoken:: jwk:: JwkSet ; 
5- use  jsonwebtoken:: { DecodingKey ,   Validation ,  decode,  decode_header} ; 
5+ use  jsonwebtoken:: { Validation ,  decode,  decode_header} ; 
66
77const  TOKEN :  & str  = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjFaNTdkX2k3VEU2S1RZNTdwS3pEeSJ9.eyJpc3MiOiJodHRwczovL2Rldi1kdXp5YXlrNC5ldS5hdXRoMC5jb20vIiwic3ViIjoiNDNxbW44c281R3VFU0U1N0Fkb3BhN09jYTZXeVNidmRAY2xpZW50cyIsImF1ZCI6Imh0dHBzOi8vZGV2LWR1enlheWs0LmV1LmF1dGgwLmNvbS9hcGkvdjIvIiwiaWF0IjoxNjIzNTg1MzAxLCJleHAiOjE2MjM2NzE3MDEsImF6cCI6IjQzcW1uOHNvNUd1RVNFNTdBZG9wYTdPY2E2V3lTYnZkIiwic2NvcGUiOiJyZWFkOnVzZXJzIiwiZ3R5IjoiY2xpZW50LWNyZWRlbnRpYWxzIn0.0MpewU1GgvRqn4F8fK_-Eu70cUgWA5JJrdbJhkCPCxXP-8WwfI-qx1ZQg2a7nbjXICYAEl-Z6z4opgy-H5fn35wGP0wywDqZpqL35IPqx6d0wRvpPMjJM75zVXuIjk7cEhDr2kaf1LOY9auWUwGzPiDB_wM-R0uvUMeRPMfrHaVN73xhAuQWVjCRBHvNscYS5-i6qBQKDMsql87dwR72DgHzMlaC8NnaGREBC-xiSamesqhKPVyGzSkFSaF3ZKpGrSDapqmHkNW9RDBE3GQ9OHM33vzUdVKOjU1g9Leb9PDt0o1U4p3NQoGJPShQ6zgWSUEaqvUZTfkbpD_DoYDRxA" ; 
88const  JWKS_REPLY :  & str  = r#" 
@@ -21,8 +21,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
2121        return  Err ( "No matching JWK found for the given kid" . into ( ) ) ; 
2222    } ; 
2323
24-     let  decoding_key = DecodingKey :: from_jwk ( jwk) ?; 
25- 
2624    let  validation = { 
2725        let  mut  validation = Validation :: new ( header. alg ) ; 
2826        validation. set_audience ( & [ "https://dev-duzyayk4.eu.auth0.com/api/v2/" ] ) ; 
@@ -31,7 +29,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
3129    } ; 
3230
3331    let  decoded_token =
34-         decode :: < HashMap < String ,  serde_json:: Value > > ( TOKEN ,  & decoding_key ,  & validation) ?; 
32+         decode :: < HashMap < String ,  serde_json:: Value > > ( TOKEN ,  & jwk . try_into ( ) ? ,  & validation) ?; 
3533
3634    println ! ( "{:#?}" ,  decoded_token) ; 
3735
Original file line number Diff line number Diff line change @@ -251,6 +251,14 @@ impl DecodingKey {
251251    } 
252252} 
253253
254+ impl  TryFrom < & Jwk >  for  DecodingKey  { 
255+     type  Error  = crate :: errors:: Error ; 
256+ 
257+     fn  try_from ( jwk :  & Jwk )  -> Result < Self >  { 
258+         Self :: from_jwk ( jwk) 
259+     } 
260+ } 
261+ 
254262/// Decode and validate a JWT 
255263/// 
256264/// If the token or its signature is invalid or the claims fail validation, it will return an error. 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments