@@ -120,7 +120,19 @@ def _encrypt(self, payload, recv, cty='JWT'):
120120 _jwe = JWE (payload , ** kwargs )
121121 return _jwe .encrypt (self .receiver_keys (recv ), context = "public" )
122122
123- def pack_init (self ):
123+ def put_together_aud (self , recv , aud ):
124+ if aud :
125+ if recv in aud :
126+ _aud = aud
127+ else :
128+ _aud = [recv ]
129+ _aud .extend (aud )
130+ else :
131+ _aud = [recv ]
132+
133+ return _aud
134+
135+ def pack_init (self , recv , aud ):
124136 """
125137 Gather initial information for the payload.
126138
@@ -129,6 +141,9 @@ def pack_init(self):
129141 argv = {'iss' : self .iss , 'iat' : utc_time_sans_frac ()}
130142 if self .lifetime :
131143 argv ['exp' ] = argv ['iat' ] + self .lifetime
144+
145+ argv ['aud' ] = self .put_together_aud (recv , aud )
146+
132147 return argv
133148
134149 def pack_key (self , owner = '' , kid = '' ):
@@ -146,17 +161,19 @@ def pack_key(self, owner='', kid=''):
146161
147162 return keys [0 ] # Might be more then one if kid == ''
148163
149- def pack (self , payload = None , kid = '' , owner = '' , recv = '' , ** kwargs ):
164+ def pack (self , payload = None , kid = '' , owner = '' , recv = '' , aud = None , ** kwargs ):
150165 """
151166
152167 :param payload: Information to be carried as payload in the JWT
153168 :param kid: Key ID
154169 :param owner: The owner of the the keys that are to be used for signing
155- :param recv: The intended receiver
170+ :param recv: The intended immediate receiver
171+ :param aud: Intended audience for this JWS/JWE, not expected to
172+ contain the recipient.
156173 :param kwargs: Extra keyword arguments
157174 :return: A signed or signed and encrypted JsonWebtoken
158175 """
159- _args = self .pack_init ()
176+ _args = self .pack_init (recv , aud )
160177
161178 try :
162179 _encrypt = kwargs ['encrypt' ]
0 commit comments