Skip to content

Commit 57732b5

Browse files
author
Peter Grant
committed
Add support for custom headers
1 parent af31311 commit 57732b5

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

jose/jwt.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@
1212
from .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

5454
def decode(token, key, algorithms=None, options=None, audience=None, issuer=None):

0 commit comments

Comments
 (0)