A cloud-based identity and access management service for securing user authentication and resource access
There is no documented Microsoft interpretation that makes an explicit expires_in: 0 a normally usable access-token lifetime.
For a security-sensitive client, rejecting that result is the correct conservative behavior. Do not invent a lifetime, substitute ext_expires_in, or parse the access token to create your own client-side validity rule. Microsoft documents that clients should treat access tokens as opaque and use MSAL's supported acquisition/cache behavior; the resource API is responsible for validating the token.
In MSAL Python's cache logic, expires_on is calculated from the current time plus expires_in. The library supplies a fallback only when expires_in is absent; an explicit integer zero therefore represents immediate expiry for cache purposes. That is consistent with the client refusing to use it, even if the token's internal claims might appear different.
A minimum supported diagnostic path is:
- Upgrade to the latest supported MSAL Python release and reproduce once with a fresh in-memory cache.
- Use
acquire_token_silent()(oracquire_token_silent_with_error()where appropriate) before interactive acquisition and let MSAL decide whether a cached token is usable. - If the interactive response again contains integer zero, stop before opening the PostgreSQL connection, as your client already does.
- Capture the MSAL correlation ID, UTC timestamp, tenant cloud, authority, requested scopes and library version. Do not capture or publish the token or authorization code.
- Open a Microsoft identity platform support case, or a minimal MSAL Python issue if support confirms a library-specific problem. The raw token-endpoint response proves this is not introduced by your PostgreSQL code.
There is no supported client-side method that can safely convert this response into a reliable positive remaining lifetime. Azure Database for PostgreSQL will validate the presented token, but relying on the database to reject an ambiguously expired token is not a substitute for correct client handling.
References: