@@ -90,7 +90,7 @@ def __post_init__(self) -> None:
9090 def decode_payload (
9191 cls ,
9292 encoded_token : str ,
93- secret : str ,
93+ secret : str | bytes ,
9494 algorithms : list [str ],
9595 issuer : list [str ] | None = None ,
9696 audience : str | Sequence [str ] | None = None ,
@@ -110,7 +110,7 @@ def decode_payload(
110110 def decode (
111111 cls ,
112112 encoded_token : str ,
113- secret : str ,
113+ secret : str | bytes ,
114114 algorithm : str ,
115115 audience : str | Sequence [str ] | None = None ,
116116 issuer : str | Sequence [str ] | None = None ,
@@ -194,12 +194,18 @@ def decode(
194194 ) as e :
195195 raise NotAuthorizedException ("Invalid token" ) from e
196196
197- def encode (self , secret : str , algorithm : str ) -> str :
197+ def encode (
198+ self ,
199+ secret : str | bytes ,
200+ algorithm : str ,
201+ headers : dict [str , Any ] | None = None ,
202+ ) -> str :
198203 """Encode the token instance into a string.
199204
200205 Args:
201206 secret: The secret with which the JWT is encoded.
202207 algorithm: The algorithm used to encode the JWT.
208+ headers: Optional headers to include in the JWT (e.g., {"kid": "..."}).
203209
204210 Returns:
205211 An encoded token string.
@@ -212,6 +218,7 @@ def encode(self, secret: str, algorithm: str) -> str:
212218 payload = {k : v for k , v in asdict (self ).items () if v is not None },
213219 key = secret ,
214220 algorithm = algorithm ,
221+ headers = headers ,
215222 )
216223 except (jwt .DecodeError , NotImplementedError ) as e :
217224 raise ImproperlyConfiguredException ("Failed to encode token" ) from e
0 commit comments