3
3
#
4
4
5
5
import base64
6
+ import json
6
7
from dataclasses import InitVar , dataclass
7
8
from datetime import datetime
8
9
from typing import Any , Mapping , Optional , Union
@@ -104,21 +105,21 @@ def __post_init__(self, parameters: Mapping[str, Any]) -> None:
104
105
)
105
106
106
107
def _get_jwt_headers (self ) -> dict [str , Any ]:
107
- """ "
108
+ """
108
109
Builds and returns the headers used when signing the JWT.
109
110
"""
110
- headers = self ._additional_jwt_headers .eval (self .config )
111
+ headers = self ._additional_jwt_headers .eval (self .config , json_loads = json . loads )
111
112
if any (prop in headers for prop in ["kid" , "alg" , "typ" , "cty" ]):
112
113
raise ValueError (
113
114
"'kid', 'alg', 'typ', 'cty' are reserved headers and should not be set as part of 'additional_jwt_headers'"
114
115
)
115
116
116
117
if self ._kid :
117
- headers ["kid" ] = self ._kid .eval (self .config )
118
+ headers ["kid" ] = self ._kid .eval (self .config , json_loads = json . loads )
118
119
if self ._typ :
119
- headers ["typ" ] = self ._typ .eval (self .config )
120
+ headers ["typ" ] = self ._typ .eval (self .config , json_loads = json . loads )
120
121
if self ._cty :
121
- headers ["cty" ] = self ._cty .eval (self .config )
122
+ headers ["cty" ] = self ._cty .eval (self .config , json_loads = json . loads )
122
123
headers ["alg" ] = self ._algorithm
123
124
return headers
124
125
@@ -130,18 +131,19 @@ def _get_jwt_payload(self) -> dict[str, Any]:
130
131
exp = now + self ._token_duration if isinstance (self ._token_duration , int ) else now
131
132
nbf = now
132
133
133
- payload = self ._additional_jwt_payload .eval (self .config )
134
+ payload = self ._additional_jwt_payload .eval (self .config , json_loads = json . loads )
134
135
if any (prop in payload for prop in ["iss" , "sub" , "aud" , "iat" , "exp" , "nbf" ]):
135
136
raise ValueError (
136
137
"'iss', 'sub', 'aud', 'iat', 'exp', 'nbf' are reserved properties and should not be set as part of 'additional_jwt_payload'"
137
138
)
138
139
139
140
if self ._iss :
140
- payload ["iss" ] = self ._iss .eval (self .config )
141
+ payload ["iss" ] = self ._iss .eval (self .config , json_loads = json . loads )
141
142
if self ._sub :
142
- payload ["sub" ] = self ._sub .eval (self .config )
143
+ payload ["sub" ] = self ._sub .eval (self .config , json_loads = json . loads )
143
144
if self ._aud :
144
- payload ["aud" ] = self ._aud .eval (self .config )
145
+ payload ["aud" ] = self ._aud .eval (self .config , json_loads = json .loads )
146
+
145
147
payload ["iat" ] = now
146
148
payload ["exp" ] = exp
147
149
payload ["nbf" ] = nbf
@@ -151,7 +153,7 @@ def _get_secret_key(self) -> str:
151
153
"""
152
154
Returns the secret key used to sign the JWT.
153
155
"""
154
- secret_key : str = self ._secret_key .eval (self .config )
156
+ secret_key : str = self ._secret_key .eval (self .config , json_loads = json . loads )
155
157
return (
156
158
base64 .b64encode (secret_key .encode ()).decode ()
157
159
if self ._base64_encode_secret_key
@@ -176,7 +178,11 @@ def _get_header_prefix(self) -> Union[str, None]:
176
178
"""
177
179
Returns the header prefix to be used when attaching the token to the request.
178
180
"""
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
+ )
180
186
181
187
@property
182
188
def auth_header (self ) -> str :
0 commit comments