How to stop QNetworkAccessManager from caching NTLM credentials?
-
Qt 5.15.2
Hello, I'm using QNetworkAccessManager for NTLM authentication. After successful authentication, QNAM caches credentials, which I don't want.
Is there any convenient way of clearing the cache or preventing QNAM from caching credentials? Or can I trick Qt into firing the authenticationRequired signal?
I've tried setting the request attributes:
- CacheLoadControlAttribute to AlwaysNetwork - didn't help
- CacheSaveControlAttribute to false - didn't help
- DoNotBufferUploadDataAttribute to true - didn't help
- AutoDeleteReplyOnFinishAttribute to true - crashed the server
- AuthenticationReuseAttribute to Manual - started caching wrong credentials
I tried using clearAccessCache and clearConnectionCache - depending on the call place, calls crashed the server, slowed down the completion of requests, or returned a 401 error or a 5 Operation Cancelled error.
I tried closing, aborting, and disconnecting replies in the authenticationRequired and finished signals:
- abort() - didn't help
- close() - sometimes returned a 5 Operation Cancelled error
- disconnect() - led to an infinite loop
I tried to manually get the cache before, inside, and after authenticationRequired - couldn't get (nullptr):
QNetworkDiskCache *diskCache = qobject_cast<QNetworkDiskCache *>(manager.cache()); QUrl url = request.url(); if (diskCache) { QNetworkCacheMetaData metaData = diskCache->metaData(url); if (metaData.isValid()) { diskCache->remove(url); } }
I tried to save a pointer to QAuthenticator inside a class derived from QNetworkReply and set the user and password to an empty string before and after authenticationRequired - didn't help.
Is there something I'm missing?
-
Hi and welcome to devnet,
Please provide a minimal compilable example that shows the issue.
You should also check with the latest Qt 6 to see if there's a difference in the behaviour.
-
Qt 5.15.2
Hello, I'm using QNetworkAccessManager for NTLM authentication. After successful authentication, QNAM caches credentials, which I don't want.
Is there any convenient way of clearing the cache or preventing QNAM from caching credentials? Or can I trick Qt into firing the authenticationRequired signal?
I've tried setting the request attributes:
- CacheLoadControlAttribute to AlwaysNetwork - didn't help
- CacheSaveControlAttribute to false - didn't help
- DoNotBufferUploadDataAttribute to true - didn't help
- AutoDeleteReplyOnFinishAttribute to true - crashed the server
- AuthenticationReuseAttribute to Manual - started caching wrong credentials
I tried using clearAccessCache and clearConnectionCache - depending on the call place, calls crashed the server, slowed down the completion of requests, or returned a 401 error or a 5 Operation Cancelled error.
I tried closing, aborting, and disconnecting replies in the authenticationRequired and finished signals:
- abort() - didn't help
- close() - sometimes returned a 5 Operation Cancelled error
- disconnect() - led to an infinite loop
I tried to manually get the cache before, inside, and after authenticationRequired - couldn't get (nullptr):
QNetworkDiskCache *diskCache = qobject_cast<QNetworkDiskCache *>(manager.cache()); QUrl url = request.url(); if (diskCache) { QNetworkCacheMetaData metaData = diskCache->metaData(url); if (metaData.isValid()) { diskCache->remove(url); } }
I tried to save a pointer to QAuthenticator inside a class derived from QNetworkReply and set the user and password to an empty string before and after authenticationRequired - didn't help.
Is there something I'm missing?
@Nerdan Disk cache (or AbstractNetworkCache you're casting to disk cache) has nothing to do with auth.
I suppose you're looking for this? https://doc.qt.io/qt-6/qnetworkaccessmanager.html#clearAccessCache
Please note, documentation is from Qt6.7, please check if your implementation is same.
-
@SGaist It's very hard to provide a minimal compilable example because it's part of a big application. Also, I've tried upgrading from Qt 5.15.2 to Qt 6.7.2, but it leads to a crash of the application, unfortunately(I've resolved all compatibility errors and installed the Qt 5 Compatibility module)
@artwaw I've tried using both clearAccessCache and clearConnectionCache without success.
I greatly appreciate your time and attempts to help.
-
@SGaist It's very hard to provide a minimal compilable example because it's part of a big application. Also, I've tried upgrading from Qt 5.15.2 to Qt 6.7.2, but it leads to a crash of the application, unfortunately(I've resolved all compatibility errors and installed the Qt 5 Compatibility module)
@artwaw I've tried using both clearAccessCache and clearConnectionCache without success.
I greatly appreciate your time and attempts to help.