@@ -25,6 +25,7 @@ pub struct CustomServiceAccount {
25
25
credentials : ApplicationCredentials ,
26
26
signer : Signer ,
27
27
tokens : RwLock < HashMap < Vec < String > , Token > > ,
28
+ subject : Option < String > ,
28
29
}
29
30
30
31
impl CustomServiceAccount {
@@ -57,11 +58,18 @@ impl CustomServiceAccount {
57
58
}
58
59
}
59
60
61
+ /// Set the `subject` to impersonate a user
62
+ pub fn with_subject ( mut self , subject : String ) -> Self {
63
+ self . subject = Some ( subject) ;
64
+ self
65
+ }
66
+
60
67
fn new ( credentials : ApplicationCredentials ) -> Result < Self , Error > {
61
68
Ok ( Self {
62
69
signer : Signer :: new ( & credentials. private_key ) ?,
63
70
credentials,
64
71
tokens : RwLock :: new ( HashMap :: new ( ) ) ,
72
+ subject : None ,
65
73
} )
66
74
}
67
75
@@ -100,7 +108,8 @@ impl ServiceAccount for CustomServiceAccount {
100
108
use hyper:: header;
101
109
use url:: form_urlencoded;
102
110
103
- let jwt = Claims :: new ( & self . credentials , scopes, None ) . to_jwt ( & self . signer ) ?;
111
+ let jwt =
112
+ Claims :: new ( & self . credentials , scopes, self . subject . as_deref ( ) ) . to_jwt ( & self . signer ) ?;
104
113
let rqbody = form_urlencoded:: Serializer :: new ( String :: new ( ) )
105
114
. extend_pairs ( & [ ( "grant_type" , GRANT_TYPE ) , ( "assertion" , jwt. as_str ( ) ) ] )
106
115
. finish ( ) ;
0 commit comments