@@ -324,15 +324,12 @@ async def _exchange_token_client_credentials(self) -> httpx.Request:
324324
325325
326326class JWTParameters (BaseModel ):
327- """JWT parameters for RFC7523OAuthClientProvider.
328-
329- This class supports both pre-built JWTs and SDK-signed JWTs.
330- """
327+ """JWT parameters."""
331328
332329 assertion : str | None = Field (
333330 default = None ,
334- description = "Pre-built JWT assertion. If provided, will be used directly "
335- "instead of generating a new assertion." ,
331+ description = "JWT assertion for JWT authentication. "
332+ "Will be used instead of generating a new assertion if provided ." ,
336333 )
337334
338335 issuer : str | None = Field (default = None , description = "Issuer for JWT assertions." )
@@ -345,36 +342,37 @@ class JWTParameters(BaseModel):
345342
346343 def to_assertion (self , with_audience_fallback : str | None = None ) -> str :
347344 if self .assertion is not None :
348- # Pre-built JWT (e.g. acquired out-of-band)
349- return self .assertion
350-
351- if not self .jwt_signing_key :
352- raise OAuthFlowError ("Missing signing key for JWT bearer grant" ) # pragma: no cover
353- if not self .issuer :
354- raise OAuthFlowError ("Missing issuer for JWT bearer grant" ) # pragma: no cover
355- if not self .subject :
356- raise OAuthFlowError ("Missing subject for JWT bearer grant" ) # pragma: no cover
357-
358- audience = self .audience if self .audience else with_audience_fallback
359- if not audience :
360- raise OAuthFlowError ("Missing audience for JWT bearer grant" ) # pragma: no cover
361-
362- now = int (time .time ())
363- claims : dict [str , Any ] = {
364- "iss" : self .issuer ,
365- "sub" : self .subject ,
366- "aud" : audience ,
367- "exp" : now + self .jwt_lifetime_seconds ,
368- "iat" : now ,
369- "jti" : str (uuid4 ()),
370- }
371- claims .update (self .claims or {})
345+ # Prebuilt JWT (e.g. acquired out-of-band)
346+ assertion = self .assertion
347+ else :
348+ if not self .jwt_signing_key :
349+ raise OAuthFlowError ("Missing signing key for JWT bearer grant" ) # pragma: no cover
350+ if not self .issuer :
351+ raise OAuthFlowError ("Missing issuer for JWT bearer grant" ) # pragma: no cover
352+ if not self .subject :
353+ raise OAuthFlowError ("Missing subject for JWT bearer grant" ) # pragma: no cover
372354
373- return jwt .encode (
374- claims ,
375- self .jwt_signing_key ,
376- algorithm = self .jwt_signing_algorithm or "RS256" ,
377- )
355+ audience = self .audience if self .audience else with_audience_fallback
356+ if not audience :
357+ raise OAuthFlowError ("Missing audience for JWT bearer grant" ) # pragma: no cover
358+
359+ now = int (time .time ())
360+ claims : dict [str , Any ] = {
361+ "iss" : self .issuer ,
362+ "sub" : self .subject ,
363+ "aud" : audience ,
364+ "exp" : now + self .jwt_lifetime_seconds ,
365+ "iat" : now ,
366+ "jti" : str (uuid4 ()),
367+ }
368+ claims .update (self .claims or {})
369+
370+ assertion = jwt .encode (
371+ claims ,
372+ self .jwt_signing_key ,
373+ algorithm = self .jwt_signing_algorithm or "RS256" ,
374+ )
375+ return assertion
378376
379377
380378class RFC7523OAuthClientProvider (OAuthClientProvider ):
0 commit comments