Skip to content

[Bug] client assetion is not within valid time range. #984

@sudoapt-getclean

Description

@sudoapt-getclean

Library version used

v1.23.0

Java version

23

Scenario

ConfidentialClient - service to service (AcquireTokenForClient)

Is this a new or an existing app?

The app is in production, and I have upgraded to a new version of MSAL

Issue description and reproduction steps

Hi,
1 hour afte we upgrade to msal v1.23.0 we started seeing this stacktrace:

Caused by: com.microsoft.aad.msal4j.MsalServiceException: AADSTS700024: Client assertion is not within its valid time range. Current time: 2025-08-29T05:47:32.1501147Z, assertion valid from 1970-01-01T00:00:00.0000000Z, expiry time of assertion 2025-08-29T00:30:05.0000000Z. Review the documentation at https://learn.microsoft.com/entra/identity-platform/certificate-credentials . Trace ID: 7a84b74b-1889-494f-b408-66e8b36c7400 Correlation ID: d75bd923-d9ca-4d18-b80e-b13851840fa9 Timestamp: 2025-08-29 05:47:32Z
	at com.microsoft.aad.msal4j.MsalServiceExceptionFactory.fromHttpResponse(MsalServiceExceptionFactory.java:38)
	at com.microsoft.aad.msal4j.TokenRequestExecutor.createAuthenticationResultFromOauthHttpResponse(TokenRequestExecutor.java:168)
	at com.microsoft.aad.msal4j.TokenRequestExecutor.executeTokenRequest(TokenRequestExecutor.java:35)
	at com.microsoft.aad.msal4j.AbstractApplicationBase.acquireTokenCommon(AbstractApplicationBase.java:75)
	at com.microsoft.aad.msal4j.AcquireTokenByAuthorizationGrantSupplier.execute(AcquireTokenByAuthorizationGrantSupplier.java:60)
	at com.microsoft.aad.msal4j.AcquireTokenByClientCredentialSupplier.acquireTokenByClientCredential(AcquireTokenByClientCredentialSupplier.java:87)
	at com.microsoft.aad.msal4j.AcquireTokenByClientCredentialSupplier.execute(AcquireTokenByClientCredentialSupplier.java:50)
	at com.microsoft.aad.msal4j.AuthenticationResultSupplier.get(AuthenticationResultSupplier.java:69)
	at com.microsoft.aad.msal4j.AuthenticationResultSupplier.get(AuthenticationResultSupplier.java:18)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)

and msal was nog longer able to aquire authenitcation tokens

Relevant code snippets

class AzureADTokenFromCertificateProvider(
  url: String,
  clientId: String,
  rsaPrivateKey: String,
  rsaCertificate: String,
  scope: String
) {

  private val app: ConfidentialClientApplication
  private val clientCredentialParam: ClientCredentialParameters

  init {
    val keyFactory = KeyFactory.getInstance("RSA")
    val pkcs8KeySpec = PKCS8EncodedKeySpec(Base64.getDecoder().decode(rsaPrivateKey))
    val privateKey = keyFactory.generatePrivate(pkcs8KeySpec)

    val certificateFactory = CertificateFactory.getInstance("X.509")
    val x509Stream = ByteArrayInputStream(Base64.getDecoder().decode(rsaCertificate))
    val certificate = certificateFactory.generateCertificate(x509Stream) as X509Certificate

    app = ConfidentialClientApplication
      .builder(clientId, ClientCredentialFactory.createFromCertificate(privateKey, certificate))
      .authority(url)
      .build()

    clientCredentialParam = ClientCredentialParameters
      .builder(setOf(scope))
      .build()
  }

  fun accessToken(): String {
    return app.acquireToken(clientCredentialParam).get().accessToken()
  }
}

Expected behavior

aquire tokens like before

Identity provider

Microsoft Entra ID (Work and School accounts and Personal Microsoft accounts)

Regression

1.22

Solution and workarounds

none found

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working, needs an investigation and a fixP1High priority items, should be done before any other workRegressionBehavior that worked in a previous release that no longer works in a newer release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions