11use async_trait:: async_trait;
2- use jsonwebtoken:: Validation ;
32use serde:: Deserialize ;
43use time:: OffsetDateTime ;
54use urlencoding:: encode;
@@ -20,8 +19,6 @@ use crate::token_source::{default_http_client, TokenSource};
2019pub struct ComputeIdentitySource {
2120 token_url : String ,
2221 client : reqwest:: Client ,
23- decoding_key : jsonwebtoken:: DecodingKey ,
24- validation : jsonwebtoken:: Validation ,
2522}
2623
2724impl std:: fmt:: Debug for ComputeIdentitySource {
@@ -39,21 +36,13 @@ impl ComputeIdentitySource {
3936 Err ( _e) => METADATA_IP . to_string ( ) ,
4037 } ;
4138
42- // Only used to extract the expiry without checking the signature.
43- let mut validation = Validation :: default ( ) ;
44- validation. insecure_disable_signature_validation ( ) ;
45- validation. set_audience ( & [ audience] ) ;
46- let decoding_key = jsonwebtoken:: DecodingKey :: from_secret ( b"" ) ;
47-
4839 Ok ( ComputeIdentitySource {
4940 token_url : format ! (
5041 "http://{}/computeMetadata/v1/instance/service-accounts/default/identity?audience={}&format=full" ,
5142 host,
5243 encode( audience)
5344 ) ,
5445 client : default_http_client ( ) ,
55- decoding_key,
56- validation,
5746 } )
5847 }
5948}
@@ -75,14 +64,11 @@ impl TokenSource for ComputeIdentitySource {
7564 . text ( )
7665 . await ?;
7766
78- let exp = jsonwebtoken:: decode :: < ExpClaim > ( & jwt, & self . decoding_key , & self . validation ) ?
79- . claims
80- . exp ;
81-
67+ let token = jsonwebtoken:: dangerous:: insecure_decode :: < ExpClaim > ( jwt. as_bytes ( ) ) ?;
8268 Ok ( Token {
8369 access_token : jwt,
8470 token_type : "Bearer" . into ( ) ,
85- expiry : OffsetDateTime :: from_unix_timestamp ( exp) . ok ( ) ,
71+ expiry : OffsetDateTime :: from_unix_timestamp ( token . claims . exp ) . ok ( ) ,
8672 } )
8773 }
8874}
0 commit comments