QAbstractOAuth Class▲
-
Header: QAbstractOAuth
-
Since: Qt 5.8
-
CMake:
find_package(Qt6 REQUIRED COMPONENTS NetworkAuth)
target_link_libraries(mytarget PRIVATE Qt6::NetworkAuth)
-
qmake: QT += networkauth
-
Inherits: QObject
-
Inherited By: QAbstractOAuth2 and QOAuth1
-
Group: QAbstractOAuth is part of oauth
Detailed Description▲
The class defines the basic interface of the OAuth authentication classes. By inheriting this class, you can create custom authentication methods for different web services.
It also contains some functions to ease the process of implementing different authentication flows.
Member Type Documentation▲
enum QAbstractOAuth::ContentType▲
Indicates the MIME Content-Type of the POST methods in authenticated calls.
Constant |
Value |
Description |
---|---|---|
QAbstractOAuth::ContentType::WwwFormUrlEncoded |
0 |
Uses application/x-www-form-urlencoded format. |
QAbstractOAuth::ContentType::Json |
1 |
Uses application/json format. |
enum QAbstractOAuth::Error▲
Indicates the latest received error.
Constant |
Value |
Description |
---|---|---|
QAbstractOAuth::Error::NoError |
0 |
No error has ocurred. |
QAbstractOAuth::Error::NetworkError |
1 |
Failed to connect to the server. |
QAbstractOAuth::Error::ServerError |
2 |
The server answered the request with an error. |
QAbstractOAuth::Error::OAuthTokenNotFoundError |
3 |
The server's response to a token request provided no token identifier. |
QAbstractOAuth::Error::OAuthTokenSecretNotFoundError |
4 |
The server's response to a token request provided no token secret. |
QAbstractOAuth::Error::OAuthCallbackNotVerified |
5 |
The authorization server has not verified the supplied callback URI in the request. This usually happens when the provided callback does not match with the callback supplied during client registration. |
enum QAbstractOAuth::Stage▲
Identifies an authentication stage. It's passed to a modifyParametersFunction so that it can make different changes to parameters at each call to it during the process of authentication.
Constant |
Value |
Description |
---|---|---|
QAbstractOAuth::Stage::RequestingTemporaryCredentials |
0 |
Preparing the temporary credentials request. |
QAbstractOAuth::Stage::RequestingAuthorization |
1 |
Preparing the authorization grant URL. |
QAbstractOAuth::Stage::RequestingAccessToken |
2 |
Preparing the token request. |
QAbstractOAuth::Stage::RefreshingAccessToken |
3 |
Preparing the access token refresh. |
enum QAbstractOAuth::Status▲
Indicates the current authentication status.
Constant |
Value |
Description |
---|---|---|
QAbstractOAuth::Status::NotAuthenticated |
0 |
No token has been retrieved. |
QAbstractOAuth::Status::TemporaryCredentialsReceived |
1 |
Temporary credentials have been received, this status is used in some OAuth authetication methods. |
QAbstractOAuth::Status::Granted |
2 |
Token credentials have been received and authenticated calls are allowed. |
QAbstractOAuth::Status::RefreshingToken |
3 |
New token credentials have been requested. |
Property Documentation▲
authorizationUrl : QUrl▲
Access functions:
-
authorizationUrl() const
-
void setAuthorizationUrl(const &url)
Notifier signal:
-
void authorizationUrlChanged(const &url)
contentType : QAbstractOAuth::ContentType▲
This property holds the Content-Type to use when sending authorization parameters.
This property controls how parameters are formatted when sent with a POST request. A suitable header is also added.
Access functions:
-
contentType() const
-
void setContentType( contentType)
Notifier signal:
-
void contentTypeChanged( contentType)
[read-only] extraTokens : const QVariantMap▲
This property holds the extra tokens received from the server.
Access functions:
-
QVariantMap extraTokens() const
Notifier signal:
-
void extraTokensChanged(const QVariantMap &tokens)
[read-only] status : const Status▲
This property holds the current authentication status.
Access functions:
-
status() const
Notifier signal:
-
void statusChanged( status)
Member Function Documentation▲
[virtual] QAbstractOAuth::~QAbstractOAuth()▲
Destroys the abstract OAuth.
QUrl QAbstractOAuth::authorizationUrl() const▲
void QAbstractOAuth::authorizeWithBrowser(const QUrl &url)▲
See Also▲
See also resourceOwnerAuthorization()
[protected] QString QAbstractOAuth::callback() const▲
Returns the current callback string corresponding to the current reply handler. The returned string is the string sent to the server to specify the callback URI, or the word identifying the alternative method in headless devices.
See Also▲
See also replyHandler(), setReplyHandler()
QString QAbstractOAuth::clientIdentifier() const▲
Returns the current client identifier used in the authentication process.
Getter function for property clientIdentifier.
See Also▲
See also setClientIdentifier()
QAbstractOAuth::ContentType QAbstractOAuth::contentType() const▲
Returns the current Content-Type used in authenticated calls.
Getter function for property contentType.
See Also▲
See also setContentType(), post()
[pure virtual] QNetworkReply *QAbstractOAuth::deleteResource(const QUrl &url, const QVariantMap ¶meters = QVariantMap())▲
Sends an authenticated DELETE request and returns a new QNetworkReply. The url and parameters are used to create the request.
QVariantMap QAbstractOAuth::extraTokens() const▲
Returns the extra tokens received from the server during authentication.
Getter function for property extraTokens.
See Also▲
See also extraTokensChanged()
[static protected] QByteArray QAbstractOAuth::generateRandomString(quint8 length)▲
Generates a random string which could be used as state or nonce. The parameter length determines the size of the generated string.
See also: The OAuth 1.0 Protocol: Nonce and Timestamp.
[pure virtual] QNetworkReply *QAbstractOAuth::get(const QUrl &url, const QVariantMap ¶meters = QVariantMap())▲
Sends an authenticated GET request and returns a new QNetworkReply. The url and parameters are used to create the request.
[pure virtual] void QAbstractOAuth::grant()▲
Override this function to implement the corresponding authentication flow in the subclasses. Client code calls this function to start the authentication workflow. This may require user interaction: for example, asking the user's authorization via a web browser. When the authentication succeeds, it should emit granted(); this gives notice that credentials are ready to be used in authenticated calls.
void QAbstractOAuth::granted()▲
This signal is emitted when the authorization flow finishes successfully.
[pure virtual] QNetworkReply *QAbstractOAuth::head(const QUrl &url, const QVariantMap ¶meters = QVariantMap())▲
Sends an authenticated HEAD request and returns a new QNetworkReply. The url and parameters are used to create the request.
QAbstractOAuth::ModifyParametersFunction QAbstractOAuth::modifyParametersFunction() const▲
Returns the current parameter-modification function.
See Also▲
See also setModifyParametersFunction(), Stage
QNetworkAccessManager *QAbstractOAuth::networkAccessManager() const▲
Returns the current network access manager used to send the requests to the server during authentication flows or to make authentication calls.
See Also▲
See also setNetworkAccessManager(), QNetworkAccessManager
[pure virtual] QNetworkReply *QAbstractOAuth::post(const QUrl &url, const QVariantMap ¶meters = QVariantMap())▲
Sends an authenticated POST request and returns a new QNetworkReply. The url and parameters are used to create the request.
[pure virtual, since 5.13] void QAbstractOAuth::prepareRequest(QNetworkRequest *request, const QByteArray &verb, const QByteArray &body = QByteArray())▲
Authorizes the given request by adding a header and body to it required for authenticated requests.
The verb must be a valid HTTP verb and the same as the one that will be used to send the request.
This function was introduced in Qt 5.13.
[pure virtual] QNetworkReply *QAbstractOAuth::put(const QUrl &url, const QVariantMap ¶meters = QVariantMap())▲
Sends an authenticated PUT request and returns a new QNetworkReply. The url and parameters are used to create the request.
QAbstractOAuthReplyHandler *QAbstractOAuth::replyHandler() const▲
Returns the reply handler currently in use.
See Also▲
See also setReplyHandler(), QAbstractOAuthReplyHandler
[virtual protected] void QAbstractOAuth::resourceOwnerAuthorization(const QUrl &url, const QMultiMap<QString, QVariant> ¶meters)▲
Builds the resource owner authorization URL to be used in the web browser: url is used as the base URL and the query is created using parameters. When the URL is ready, the authorizeWithBrowser() signal will be emitted with the generated URL.
See Also▲
See also authorizeWithBrowser()
void QAbstractOAuth::setAuthorizationUrl(const QUrl &url)▲
Sets the authorization request URL to url. This address will be used to allow the user to grant the application the ability to make authenticated calls on behalf of the user.
Setter function for property authorizationUrl.
See Also▲
See also authorizationUrl()
void QAbstractOAuth::setClientIdentifier(const QString &clientIdentifier)▲
Sets the current client identifier to clientIdentifier.
Setter function for property clientIdentifier.
See Also▲
See also clientIdentifier()
void QAbstractOAuth::setContentType(QAbstractOAuth::ContentType contentType)▲
Sets the current Content-Type to contentType.
Setter function for property contentType.
See Also▲
See also contentType()
void QAbstractOAuth::setModifyParametersFunction(const QAbstractOAuth::ModifyParametersFunction &modifyParametersFunction)▲
Sets the parameter-modification function modifyParametersFunction. This function is used to customize the parameters sent to the server during a specified authorization stage. The number of calls to this function depends on the flow used during the authentication.
See Also▲
See also modifyParametersFunction(), Stage
void QAbstractOAuth::setNetworkAccessManager(QNetworkAccessManager *networkAccessManager)▲
Sets the network manager to networkAccessManager. QAbstractOAuth does not take ownership of networkAccessManager. If no custom network access manager is set, an internal network access manager is used. This network access manager will be used to make the request to the authentication server and the authenticated request to the web service.
See Also▲
See also networkAccessManager(), QNetworkAccessManager
void QAbstractOAuth::setReplyHandler(QAbstractOAuthReplyHandler *handler)▲
Sets the current reply handler to handler.
Does not take ownership of handler.
See Also▲
See also replyHandler()
[protected] void QAbstractOAuth::setStatus(QAbstractOAuth::Status status)▲
Sets the current status to status. This method is for use by classes based on QAbstractOAuth.
See Also▲
See also status()
void QAbstractOAuth::setToken(const QString &token)▲
Sets the token used to sign authenticated requests to token.
Setter function for property token.
See Also▲
See also token()