1212from .utils import timedelta_total_seconds
1313
1414
15- def encode (claims , key , algorithm = None ):
15+ def encode (claims , key , algorithm = None , headers = None ):
1616 """Encodes a claims set and returns a JWT string.
1717
1818 JWTs are JWS signed objects with a few reserved claims.
1919
2020 Args:
2121 claims (dict): A claims set to sign
2222 key (str): The key to use for signing the claim set
23+ algorithm (str, optional): The algorithm to use for signing the
24+ the claims. Defaults to HS256.
2325 headers (dict, optional): A set of headers that will be added to
2426 the default headers. Any headers that are added as additional
2527 headers will override the default headers.
26- algorithm (str, optional): The algorithm to use for signing the
27- the claims. Defaults to HS256.
2828
2929 Returns:
3030 str: The string representation of the header, claims, and signature.
@@ -46,9 +46,9 @@ def encode(claims, key, algorithm=None):
4646 claims [time_claim ] = timegm (claims [time_claim ].utctimetuple ())
4747
4848 if algorithm :
49- return jws .sign (claims , key , algorithm = algorithm )
49+ return jws .sign (claims , key , headers = headers , algorithm = algorithm )
5050
51- return jws .sign (claims , key )
51+ return jws .sign (claims , key , headers = headers )
5252
5353
5454def decode (token , key , algorithms = None , options = None , audience = None , issuer = None ):
0 commit comments