The QAbstractOAuth class is the base of all implementations of OAuth authentication methods. More...
Header: | #include <QAbstractOAuth> |
qmake: | QT += networkauth |
Since: | Qt 5.8 |
Inherits: | QObject |
Inherited By: |
enum | ContentType { WwwFormUrlEncoded, Json } |
enum | Error { NoError, NetworkError, ServerError, OAuthTokenNotFoundError, OAuthTokenSecretNotFoundError, OAuthCallbackNotVerified } |
typedef | ModifyParametersFunction |
enum | Stage { RequestingTemporaryCredentials, RequestingAuthorization, RequestingAccessToken, RefreshingAccessToken } |
enum | Status { NotAuthenticated, TemporaryCredentialsReceived, Granted, RefreshingToken } |
|
|
virtual | ~QAbstractOAuth() |
QUrl | authorizationUrl() const |
QString | clientIdentifier() const |
QAbstractOAuth::ContentType | contentType() const |
virtual QNetworkReply * | deleteResource(const QUrl &url, const QVariantMap ¶meters = ...) = 0 |
QVariantMap | extraTokens() const |
virtual QNetworkReply * | get(const QUrl &url, const QVariantMap ¶meters = ...) = 0 |
virtual QNetworkReply * | head(const QUrl &url, const QVariantMap ¶meters = ...) = 0 |
QAbstractOAuth::ModifyParametersFunction | modifyParametersFunction() const |
QNetworkAccessManager * | networkAccessManager() const |
virtual QNetworkReply * | post(const QUrl &url, const QVariantMap ¶meters = ...) = 0 |
virtual QNetworkReply * | put(const QUrl &url, const QVariantMap ¶meters = ...) = 0 |
QAbstractOAuthReplyHandler * | replyHandler() const |
void | setAuthorizationUrl(const QUrl &url) |
void | setClientIdentifier(const QString &clientIdentifier) |
void | setContentType(QAbstractOAuth::ContentType contentType) |
void | setModifyParametersFunction(const QAbstractOAuth::ModifyParametersFunction &modifyParametersFunction) |
void | setNetworkAccessManager(QNetworkAccessManager *networkAccessManager) |
void | setReplyHandler(QAbstractOAuthReplyHandler *handler) |
void | setToken(const QString &token) |
QAbstractOAuth::Status | status() const |
QString | token() const |
virtual void | grant() = 0 |
void | authorizationUrlChanged(const QUrl &url) |
void | authorizeWithBrowser(const QUrl &url) |
void | clientIdentifierChanged(const QString &clientIdentifier) |
void | contentTypeChanged(QAbstractOAuth::ContentType contentType) |
void | extraTokensChanged(const QVariantMap &tokens) |
void | finished(QNetworkReply *reply) |
void | granted() |
void | replyDataReceived(const QByteArray &data) |
void | requestFailed(const QAbstractOAuth::Error error) |
void | statusChanged(QAbstractOAuth::Status status) |
void | tokenChanged(const QString &token) |
QAbstractOAuth(QAbstractOAuthPrivate &, QObject *parent = nullptr) | |
QString | callback() const |
virtual void | resourceOwnerAuthorization(const QUrl &url, const QVariantMap ¶meters) |
void | setStatus(QAbstractOAuth::Status status) |
QByteArray | generateRandomString(quint8 length) |
The QAbstractOAuth class is the base of all implementations of OAuth authentication methods.
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.
Indicates the MIME Content-Type of the POST methods in authenticated calls.
Constant | Value | Description |
---|---|---|
QAbstractOAuth::WwwFormUrlEncoded |
0 |
Uses application/x-www-form-urlencoded format. |
QAbstractOAuth::Json |
1 |
Uses application/json format. |
Indicates the latest received error.
Constant | Value | Description |
---|---|---|
QAbstractOAuth::NoError |
0 |
No error has ocurred. |
QAbstractOAuth::NetworkError |
1 |
Failed to connect to the server. |
QAbstractOAuth::ServerError |
2 |
The server answered the request with an error. |
QAbstractOAuth::OAuthTokenNotFoundError |
3 |
The server's response to a token request provided no token identifier. |
QAbstractOAuth::OAuthTokenSecretNotFoundError |
4 |
The server's response to a token request provided no token secret. |
QAbstractOAuth::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. |
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::RequestingTemporaryCredentials |
0 |
Preparing the temporary credentials request. |
QAbstractOAuth::RequestingAuthorization |
1 |
Preparing the authorization grant URL. |
QAbstractOAuth::RequestingAccessToken |
2 |
Preparing the token request. |
QAbstractOAuth::RefreshingAccessToken |
3 |
Preparing the access token refresh. |
Indicates the current authentication status.
Constant | Value | Description |
---|---|---|
QAbstractOAuth::NotAuthenticated |
0 |
No token has been retrieved. |
QAbstractOAuth::TemporaryCredentialsReceived |
1 |
Temporary credentials have been received, this status is used in some OAuth authetication methods. |
QAbstractOAuth::Granted |
2 |
Token credentials have been received and authenticated calls are allowed. |
QAbstractOAuth::RefreshingToken |
3 |
New token credentials have been requested. |
This property holds the URL used to request the Resource Owner Authorization as described in: The OAuth 1.0 Protocol: Resource Owner Authorization
Access functions:
QUrl | authorizationUrl() const |
void | setAuthorizationUrl(const QUrl &url) |
Notifier signal:
void | authorizationUrlChanged(const QUrl &url) |
Access functions:
QString | clientIdentifier() const |
void | setClientIdentifier(const QString &clientIdentifier) |
Notifier signal:
void | clientIdentifierChanged(const QString &clientIdentifier) |
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:
QAbstractOAuth::ContentType | contentType() const |
void | setContentType(QAbstractOAuth::ContentType contentType) |
Notifier signal:
void | contentTypeChanged(QAbstractOAuth::ContentType contentType) |
This property holds the extra tokens received from the server.
Access functions:
QVariantMap | extraTokens() const |
Notifier signal:
void | extraTokensChanged(const QVariantMap &tokens) |
This property holds the current authentication status.
Access functions:
QAbstractOAuth::Status | status() const |
Notifier signal:
void | statusChanged(QAbstractOAuth::Status status) |
Access functions:
Notifier signal:
void | tokenChanged(const QString &token) |
[protected]
QAbstractOAuth::QAbstractOAuth(QAbstractOAuthPrivate &, QObject *parent = nullptr)Default constructs an instance of QAbstractOAuth.
[virtual]
QAbstractOAuth::~QAbstractOAuth()Destroys the abstract OAuth.
Returns the authorization request URL.
Note: Getter function for property authorizationUrl.
See also setAuthorizationUrl().
[signal]
void QAbstractOAuth::authorizeWithBrowser(const
QUrl &url)This signal is emitted when the url generated by resourceOwnerAuthorization() is ready to be used in the web browser to allow the application to impersonate the user.
See also resourceOwnerAuthorization().
[protected]
QString QAbstractOAuth::callback() constReturns 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 replyHandler() and setReplyHandler().
Returns the current client identifier used in the authentication process.
Note: Getter function for property clientIdentifier.
See also setClientIdentifier().
Returns the current Content-Type used in authenticated calls.
Note: Getter function for property contentType.
See also setContentType() and post().
[pure virtual]
QNetworkReply *QAbstractOAuth::deleteResource(const QUrl &url, const QVariantMap ¶meters =
...)Sends an authenticated DELETE request and returns a new QNetworkReply. The url and parameters are used to create the request.
See also: Hypertext Transfer Protocol -- HTTP/1.1: DELETE
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
Returns the extra tokens received from the server during authentication.
Note: Getter function for property extraTokens.
See also extraTokensChanged().
[signal]
void QAbstractOAuth::finished(QNetworkReply *reply)[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 = ...)Sends an authenticated GET request and returns a new QNetworkReply. The url and parameters are used to create the request.
See also: Hypertext Transfer Protocol -- HTTP/1.1: GET
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
[pure virtual slot]
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.
[signal]
void QAbstractOAuth::granted()This signal is emitted when the authorization flow finishes successfully.
[pure virtual]
QNetworkReply *QAbstractOAuth::head(const QUrl &url, const QVariantMap ¶meters = ...)Sends an authenticated HEAD request and returns a new QNetworkReply. The url and parameters are used to create the request.
See also: Hypertext Transfer Protocol -- HTTP/1.1: HEAD
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
Returns the current parameter-modification function.
See also ModifyParametersFunction, setModifyParametersFunction(), and Stage.
Returns the current network access manager used to send the requests to the server during authentication flows or to make authentication calls.
See also setNetworkAccessManager() and QNetworkAccessManager.
[pure virtual]
QNetworkReply *QAbstractOAuth::post(const QUrl &url, const QVariantMap ¶meters = ...)Sends an authenticated POST request and returns a new QNetworkReply. The url and parameters are used to create the request.
See also: Hypertext Transfer Protocol -- HTTP/1.1: POST
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
[pure virtual]
QNetworkReply *QAbstractOAuth::put(const QUrl &url, const QVariantMap ¶meters = ...)Sends an authenticated PUT request and returns a new QNetworkReply. The url and parameters are used to create the request.
See also: Hypertext Transfer Protocol -- HTTP/1.1: PUT
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
[signal]
void QAbstractOAuth::replyDataReceived(const QByteArray &data)Returns the reply handler currently in use.
See also setReplyHandler() and QAbstractOAuthReplyHandler.
[signal]
void QAbstractOAuth::requestFailed(const QAbstractOAuth::Error error)[virtual protected]
void QAbstractOAuth::resourceOwnerAuthorization(const QUrl &url, const QVariantMap
¶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 authorizeWithBrowser().
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.
Note: Setter function for property authorizationUrl.
See also authorizationUrl().
Sets the current client identifier to clientIdentifier.
Note: Setter function for property clientIdentifier.
See also clientIdentifier().
Sets the current Content-Type to contentType.
Note: Setter function for property contentType.
See also contentType().
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 modifyParametersFunction(), ModifyParametersFunction, and Stage.
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 networkAccessManager() and QNetworkAccessManager.
Sets the current reply handler to handler.
Note: Does not take ownership of handler.
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 status().
Sets the token used to sign authenticated requests to token.
Note: Setter function for property token.
See also token().
Returns the current authentication status.
Note: Getter function for property status.
See also setStatus() and Status.
Returns the token used to sign the authenticated requests.
Note: Getter function for property token.
See also setToken().