@@ -120,7 +120,19 @@ def _encrypt(self, payload, recv, cty='JWT'):
120
120
_jwe = JWE (payload , ** kwargs )
121
121
return _jwe .encrypt (self .receiver_keys (recv ), context = "public" )
122
122
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 ):
124
136
"""
125
137
Gather initial information for the payload.
126
138
@@ -129,6 +141,9 @@ def pack_init(self):
129
141
argv = {'iss' : self .iss , 'iat' : utc_time_sans_frac ()}
130
142
if self .lifetime :
131
143
argv ['exp' ] = argv ['iat' ] + self .lifetime
144
+
145
+ argv ['aud' ] = self .put_together_aud (recv , aud )
146
+
132
147
return argv
133
148
134
149
def pack_key (self , owner = '' , kid = '' ):
@@ -146,17 +161,19 @@ def pack_key(self, owner='', kid=''):
146
161
147
162
return keys [0 ] # Might be more then one if kid == ''
148
163
149
- def pack (self , payload = None , kid = '' , owner = '' , recv = '' , ** kwargs ):
164
+ def pack (self , payload = None , kid = '' , owner = '' , recv = '' , aud = None , ** kwargs ):
150
165
"""
151
166
152
167
:param payload: Information to be carried as payload in the JWT
153
168
:param kid: Key ID
154
169
: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.
156
173
:param kwargs: Extra keyword arguments
157
174
:return: A signed or signed and encrypted JsonWebtoken
158
175
"""
159
- _args = self .pack_init ()
176
+ _args = self .pack_init (recv , aud )
160
177
161
178
try :
162
179
_encrypt = kwargs ['encrypt' ]
0 commit comments