1+ import json
12from datetime import timedelta
2- from typing import Union
3+ from typing import Optional , Type , Union
34
45import jwt
56from django .utils .translation import gettext_lazy as _
@@ -38,6 +39,7 @@ def __init__(
3839 issuer = None ,
3940 jwk_url : str = None ,
4041 leeway : Union [float , int , timedelta ] = None ,
42+ json_encoder : Optional [Type [json .JSONEncoder ]] = None ,
4143 ):
4244 self ._validate_algorithm (algorithm )
4345
@@ -53,6 +55,7 @@ def __init__(
5355 self .jwks_client = None
5456
5557 self .leeway = leeway
58+ self .json_encoder = json_encoder
5659
5760 def _validate_algorithm (self , algorithm ):
5861 """
@@ -107,7 +110,12 @@ def encode(self, payload):
107110 if self .issuer is not None :
108111 jwt_payload ["iss" ] = self .issuer
109112
110- token = jwt .encode (jwt_payload , self .signing_key , algorithm = self .algorithm )
113+ token = jwt .encode (
114+ jwt_payload ,
115+ self .signing_key ,
116+ algorithm = self .algorithm ,
117+ json_encoder = self .json_encoder ,
118+ )
111119 if isinstance (token , bytes ):
112120 # For PyJWT <= 1.7.1
113121 return token .decode ("utf-8" )
0 commit comments