@@ -715,6 +715,17 @@ def get_client_assertion():
715715 self ._region_detected = None
716716 self .client , self ._regional_client = self ._build_client (
717717 client_credential , self .authority )
718+ # Warn if using a static string/bytes client_assertion (discouraged for long-running apps)
719+ if client_credential and isinstance (client_credential .get ("client_assertion" ), (str , bytes )):
720+ warnings .warn (
721+ "Passing a static string/bytes 'client_assertion' is "
722+ "discouraged because the JWT will eventually expire. "
723+ "Pass a no-arg callable instead (optionally wrapped in "
724+ "msal.AutoRefresher) so MSAL can obtain a fresh "
725+ "assertion on demand. "
726+ "See https://github.com/AzureAD/microsoft-authentication-library-for-python/issues/746" ,
727+ DeprecationWarning , stacklevel = 2 )
728+
718729 self .authority_groups = {}
719730 self ._telemetry_buffer = {}
720731 self ._telemetry_lock = Lock ()
@@ -846,19 +857,6 @@ def _build_client(self, client_credential, authority, skip_regional_client=False
846857 # so that we can ignore an empty string came from an empty ENV VAR.
847858 if client_credential .get ("client_assertion" ):
848859 client_assertion = client_credential ['client_assertion' ]
849- if not callable (client_assertion ):
850- # Soft-deprecation: a fixed string assertion has a fixed
851- # expiration. Long-running apps should pass a callable so
852- # MSAL can fetch a fresh assertion on demand. See
853- # https://github.com/AzureAD/microsoft-authentication-library-for-python/issues/746
854- warnings .warn (
855- "Passing a static string/bytes 'client_assertion' is "
856- "discouraged because the JWT will eventually expire. "
857- "Pass a no-arg callable instead (optionally wrapped in "
858- "msal.AutoRefresher) so MSAL can obtain a fresh "
859- "assertion on demand. "
860- "See https://github.com/AzureAD/microsoft-authentication-library-for-python/issues/746" ,
861- DeprecationWarning , stacklevel = 2 )
862860 else :
863861 headers = {}
864862 sha1_thumbprint = sha256_thumbprint = None
0 commit comments