[Development] [API Change] New authentication method in QNetworkAccessManager
Konstantin Ritt
ritt.ks at gmail.com
Sun Mar 9 17:16:38 CET 2014
2014-03-09 16:10 GMT+02:00 Kurt Pattyn <pattyn.kurt at gmail.com>:
> Currently, QNAM stalls when authentication is required (also see:
> https://bugreports.qt-project.org/browse/QTBUG-16251).
> Also, the connection between the authenticationRequired signal and the
> slot must be a direct connection.
> This is problematic when an application wants to show a login dialogbox
> for instance.
>
>
QAuthenticator doesn't seem to make any difference in this case. Am I
missing something?
Anyways, this sounds more convenient than the current behavior.
> I propose to change this implementation by using a delegate authenticator
> instead.
>
> class QAuthenticator
> {
> …
> protected Q_SLOTS:
>
> //this method should be called asynchronously from QNAM
> void authenticate(QNetworkReply *reply) {
> if (doAuthenticate(reply))
> Q_EMIT authenticated();
> else
> Q_EMIT authenticationFailed();
> }
> ...
>
> protected:
> //return false if the request should be stopped (authentication
> denied)
> //return true if authentication should continue
> virtual bool doAuthenticate(QNetworkReply *reply) = 0;
> ...
> }
>
> //example use
> class MyAuthenticator: public QAuthenticator
> {
> bool doAuthenticate(QNetworkReply *reply) {
> setUser();
> setPassword();
> setOption();
>
> //whatever is required
>
> return true;
> }
> }
>
> The QNetworkRequest class would be extended with a setAuthenticator()
> method, as follows:
>
> class QNetworkRequest
> {
> ...
> void setAuthenticator(QAuthenticator *authenticator);
> ...
> }
>
> Usage:
> MyAuthenticator *auth = new MyAuthenticator;
> networkRequest.setAuthenticator(auth);
>
> Another option is to add the setAuthenticator() method to the QNAM class.
>
> When this would be implemented, the authenticationRequired() signal would
> become obsolete.
>
>
> What are your opinions on this?
>
>
> Note: QWebSocketServer uses the same blocking signal for CORS
> authentication
> (this was merely done to be inline with the QNAM way of working).
>
> Cheers,
>
> Kurt
>
>
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/development
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20140309/2dcad3cd/attachment.html>
More information about the Development
mailing list