33#
44
55import base64
6+ import json
67from dataclasses import InitVar , dataclass
78from datetime import datetime
89from typing import Any , Mapping , Optional , Union
@@ -104,21 +105,21 @@ def __post_init__(self, parameters: Mapping[str, Any]) -> None:
104105 )
105106
106107 def _get_jwt_headers (self ) -> dict [str , Any ]:
107- """ "
108+ """
108109 Builds and returns the headers used when signing the JWT.
109110 """
110- headers = self ._additional_jwt_headers .eval (self .config )
111+ headers = self ._additional_jwt_headers .eval (self .config , json_loads = json . loads )
111112 if any (prop in headers for prop in ["kid" , "alg" , "typ" , "cty" ]):
112113 raise ValueError (
113114 "'kid', 'alg', 'typ', 'cty' are reserved headers and should not be set as part of 'additional_jwt_headers'"
114115 )
115116
116117 if self ._kid :
117- headers ["kid" ] = self ._kid .eval (self .config )
118+ headers ["kid" ] = self ._kid .eval (self .config , json_loads = json . loads )
118119 if self ._typ :
119- headers ["typ" ] = self ._typ .eval (self .config )
120+ headers ["typ" ] = self ._typ .eval (self .config , json_loads = json . loads )
120121 if self ._cty :
121- headers ["cty" ] = self ._cty .eval (self .config )
122+ headers ["cty" ] = self ._cty .eval (self .config , json_loads = json . loads )
122123 headers ["alg" ] = self ._algorithm
123124 return headers
124125
@@ -130,18 +131,19 @@ def _get_jwt_payload(self) -> dict[str, Any]:
130131 exp = now + self ._token_duration if isinstance (self ._token_duration , int ) else now
131132 nbf = now
132133
133- payload = self ._additional_jwt_payload .eval (self .config )
134+ payload = self ._additional_jwt_payload .eval (self .config , json_loads = json . loads )
134135 if any (prop in payload for prop in ["iss" , "sub" , "aud" , "iat" , "exp" , "nbf" ]):
135136 raise ValueError (
136137 "'iss', 'sub', 'aud', 'iat', 'exp', 'nbf' are reserved properties and should not be set as part of 'additional_jwt_payload'"
137138 )
138139
139140 if self ._iss :
140- payload ["iss" ] = self ._iss .eval (self .config )
141+ payload ["iss" ] = self ._iss .eval (self .config , json_loads = json . loads )
141142 if self ._sub :
142- payload ["sub" ] = self ._sub .eval (self .config )
143+ payload ["sub" ] = self ._sub .eval (self .config , json_loads = json . loads )
143144 if self ._aud :
144- payload ["aud" ] = self ._aud .eval (self .config )
145+ payload ["aud" ] = self ._aud .eval (self .config , json_loads = json .loads )
146+
145147 payload ["iat" ] = now
146148 payload ["exp" ] = exp
147149 payload ["nbf" ] = nbf
@@ -151,7 +153,7 @@ def _get_secret_key(self) -> str:
151153 """
152154 Returns the secret key used to sign the JWT.
153155 """
154- secret_key : str = self ._secret_key .eval (self .config )
156+ secret_key : str = self ._secret_key .eval (self .config , json_loads = json . loads )
155157 return (
156158 base64 .b64encode (secret_key .encode ()).decode ()
157159 if self ._base64_encode_secret_key
@@ -176,7 +178,11 @@ def _get_header_prefix(self) -> Union[str, None]:
176178 """
177179 Returns the header prefix to be used when attaching the token to the request.
178180 """
179- return self ._header_prefix .eval (self .config ) if self ._header_prefix else None
181+ return (
182+ self ._header_prefix .eval (self .config , json_loads = json .loads )
183+ if self ._header_prefix
184+ else None
185+ )
180186
181187 @property
182188 def auth_header (self ) -> str :
0 commit comments