The QAuthenticator class provides an authentication object. More...
Header: | #include <QAuthenticator> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Network) target_link_libraries(mytarget PRIVATE Qt6::Network) |
qmake: | QT += network |
Note: All functions in this class are reentrant.
QAuthenticator(const QAuthenticator &other) | |
QAuthenticator() | |
QAuthenticator & | operator=(const QAuthenticator &other) |
~QAuthenticator() | |
bool | isNull() const |
QVariant | option(const QString &opt) const |
QVariantHash | options() const |
QString | password() const |
QString | realm() const |
void | setOption(const QString &opt, const QVariant &value) |
void | setPassword(const QString &password) |
void | setUser(const QString &user) |
QString | user() const |
bool | operator!=(const QAuthenticator &other) const |
bool | operator==(const QAuthenticator &other) const |
The QAuthenticator class is usually used in the authenticationRequired() and proxyAuthenticationRequired() signals of QNetworkAccessManager and QAbstractSocket. The class provides a way to pass back the required authentication information to the socket when accessing services that require authentication.
QAuthenticator supports the following authentication methods:
In addition to the username and password required for authentication, a QAuthenticator object can also contain additional options. The options() function can be used to query incoming options sent by the server; the setOption() function can be used to set outgoing options, to be processed by the authenticator calculation. The options accepted and provided depend on the authentication type (see method()).
The following tables list known incoming options as well as accepted outgoing options. The list of incoming options is not exhaustive, since servers may include additional information at any time. The list of outgoing options is exhaustive, however, and no unknown options will be treated or sent back to the server.
Option | Direction | Type | Description |
---|---|---|---|
realm |
Incoming | QString | Contains the realm of the authentication, the same as realm() |
The Basic authentication mechanism supports no outgoing options.
The NTLM authentication mechanism currently supports no incoming or outgoing options. On Windows, if no user has been set, domain\user credentials will be searched for on the local system to enable Single-Sign-On functionality.
Option | Direction | Type | Description |
---|---|---|---|
realm |
Incoming | QString | Contains the realm of the authentication, the same as realm() |
The Digest-MD5 authentication mechanism supports no outgoing options.
Option | Direction | Type | Description |
---|---|---|---|
spn |
Outgoing | QString | Provides a custom SPN. |
This authentication mechanism currently supports no incoming options.
The spn
property is used on Windows clients when an SSPI library is used. If the property is not set, a default SPN will be used. The default SPN on Windows is HTTP/<hostname>
.
Other operating systems use GSSAPI libraries. For that it is expected that KDC is set up, and the credentials can be fetched from it. The backend always uses HTTPS@<hostname>
as an SPN.
See also QSslSocket.
Constructs a copy of other.
Constructs an empty authentication object.
Assigns the contents of other to this authenticator.
Destructs the object.
Returns true
if the object has not been initialized. Returns false
if non-const member functions have been called, or the content was constructed or copied from another initialized QAuthenticator object.
Returns the value related to option opt if it was set by the server. See the Options section for more information on incoming options. If option opt isn't found, an invalid QVariant will be returned.
See also setOption(), options(), and QAuthenticator options.
Returns all incoming options set in this QAuthenticator object by parsing the server reply. See the Options section for more information on incoming options.
See also option() and QAuthenticator options.
Returns the password used for authentication.
See also setPassword().
Returns the realm requiring authentication.
Sets the outgoing option opt to value value. See the Options section for more information on outgoing options.
See also options(), option(), and QAuthenticator options.
Sets the password used for authentication.
See also password() and QNetworkAccessManager::authenticationRequired().
Sets the user used for authentication.
See also user() and QNetworkAccessManager::authenticationRequired().
Returns the user used for authentication.
See also setUser().
Returns true
if this authenticator is different from other; otherwise returns false
.
Returns true
if this authenticator is identical to other; otherwise returns false
.