QAbstractOAuth Class
The QAbstractOAuth class is the base of all implementations of OAuth authentication methods. 更多...
头文件: | #include <QAbstractOAuth> |
qmake: | QT += networkauth |
开始支持版本: | Qt 5.8 |
基类: | QObject |
派生类: |
公有类型
enum | ContentType { WwwFormUrlEncoded, Json } |
enum | Error { NoError, NetworkError, ServerError, OAuthTokenNotFoundError, OAuthTokenSecretNotFoundError, OAuthCallbackNotVerified } |
typedef | ModifyParametersFunction |
enum | Stage { RequestingTemporaryCredentials, RequestingAuthorization, RequestingAccessToken } |
enum | Status { NotAuthenticated, TemporaryCredentialsReceived, Granted, RefreshingToken } |
属性
- authorizationUrl : QUrl
- contentType : QAbstractOAuth::ContentType
- extraTokens : const QVariantMap
- status : const Status
- 1 个属性继承自 QObject
公有函数
virtual | ~QAbstractOAuth() |
QUrl | authorizationUrl() const |
virtual QString | clientIdentifier() const = 0 |
ContentType | contentType() const |
virtual QNetworkReply * | deleteResource(const QUrl &url, const QVariantMap ¶meters = QVariantMap()) = 0 |
QVariantMap | extraTokens() const |
virtual QNetworkReply * | get(const QUrl &url, const QVariantMap ¶meters = QVariantMap()) = 0 |
virtual QNetworkReply * | head(const QUrl &url, const QVariantMap ¶meters = QVariantMap()) = 0 |
ModifyParametersFunction | modifyParametersFunction() const |
QNetworkAccessManager * | networkAccessManager() const |
virtual QNetworkReply * | post(const QUrl &url, const QVariantMap ¶meters = QVariantMap()) = 0 |
QAbstractOAuthReplyHandler * | replyHandler() const |
void | setAuthorizationUrl(const QUrl &url) |
virtual void | setClientIdentifier(const QString &clientIdentifier) = 0 |
void | setContentType(ContentType contentType) |
void | setModifyParametersFunction(const ModifyParametersFunction &modifyParametersFunction) |
void | setNetworkAccessManager(QNetworkAccessManager *networkAccessManager) |
void | setReplyHandler(QAbstractOAuthReplyHandler *handler) |
virtual void | setToken(const QString &token) = 0 |
Status | status() const |
virtual QString | token() const = 0 |
- 32 个公有函数继承自 QObject
公有槽函数
virtual void | grant() = 0 |
- 1 个公有槽函数继承自 QObject
信号
void | authorizationUrlChanged(const QUrl &url) |
void | authorizeWithBrowser(const QUrl &url) |
void | clientIdentifierChanged(const QString &clientIdentifier) |
void | contentTypeChanged(ContentType contentType) |
void | extraTokensChanged(const QVariantMap &tokens) |
void | finished(QNetworkReply *reply) |
void | granted() |
void | replyDataReceived(const QByteArray &data) |
void | requestFailed(const Error error) |
void | statusChanged(Status status) |
void | tokenChanged(const QString &token) |
- 2 个信号继承自 QObject
受保护的函数
QAbstractOAuth(QAbstractOAuthPrivate &, QObject *parent = nullptr) | |
QString | callback() const |
virtual void | resourceOwnerAuthorization(const QUrl &url, const QVariantMap ¶meters) |
void | setStatus(Status status) |
- 9 个受保护的函数继承自 QObject
Static Protected Members
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.
成员类型
enum QAbstractOAuth::ContentType
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. |
enum QAbstractOAuth::Error
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. |
typedef QAbstractOAuth::ModifyParametersFunction
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::RequestingTemporaryCredentials | 0 | Preparing the temporary credentials request. |
QAbstractOAuth::RequestingAuthorization | 1 | Preparing the authorization grant URL. |
QAbstractOAuth::RequestingAccessToken | 2 | Preparing the token request. |
enum QAbstractOAuth::Status
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. |
属性
authorizationUrl : QUrl
This property holds the URL used to request the Resource Owner Authorization as described in: The OAuth 1.0 Protocol: Resource Owner Authorization
访问函数:
QUrl | authorizationUrl() const |
void | setAuthorizationUrl(const QUrl &url) |
Notifier signal:
void | authorizationUrlChanged(const QUrl &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.
访问函数:
ContentType | contentType() const |
void | setContentType(ContentType contentType) |
Notifier signal:
void | contentTypeChanged(ContentType contentType) |
extraTokens : const QVariantMap
This property holds the extra tokens received from the server.
访问函数:
QVariantMap | extraTokens() const |
Notifier signal:
void | extraTokensChanged(const QVariantMap &tokens) |
status : const Status
This property holds the current authentication status.
访问函数:
Status | status() const |
Notifier signal:
void | statusChanged(Status status) |
成员函数
[protected]
QAbstractOAuth::QAbstractOAuth(QAbstractOAuthPrivate &, QObject *parent = nullptr)
Copy constructor.
[virtual]
QAbstractOAuth::~QAbstractOAuth()
Destroys the abstract OAuth.
QUrl QAbstractOAuth::authorizationUrl() const
Returns the authorization request URL.
Note: Getter function for property authorizationUrl.
参见 setAuthorizationUrl().
[signal]
void QAbstractOAuth::authorizeWithBrowser(const QUrl &url)
[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.
参见 replyHandler() and setReplyHandler().
[pure virtual]
QString QAbstractOAuth::clientIdentifier() const
参见 setClientIdentifier().
[signal]
void QAbstractOAuth::clientIdentifierChanged(const QString &clientIdentifier)
ContentType QAbstractOAuth::contentType() const
Returns the current Content-Type used in authenticated calls.
Note: Getter function for property contentType.
参见 setContentType() and post().
[pure virtual]
QNetworkReply *QAbstractOAuth::deleteResource(const QUrl &url, const QVariantMap ¶meters = QVariantMap())
QVariantMap QAbstractOAuth::extraTokens() const
Returns the extra tokens received from the server during authentication.
Note: Getter function for property extraTokens.
参见 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.
参见: The OAuth 1.0 Protocol: Nonce and Timestamp.
[pure virtual]
QNetworkReply *QAbstractOAuth::get(const QUrl &url, const QVariantMap ¶meters = QVariantMap())
[pure virtual slot]
void QAbstractOAuth::grant()
[signal]
void QAbstractOAuth::granted()
[pure virtual]
QNetworkReply *QAbstractOAuth::head(const QUrl &url, const QVariantMap ¶meters = QVariantMap())
ModifyParametersFunction QAbstractOAuth::modifyParametersFunction() const
Returns the current parameter-modification function.
参见 ModifyParametersFunction, setModifyParametersFunction(), and 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.
参见 setNetworkAccessManager() and QNetworkAccessManager.
[pure virtual]
QNetworkReply *QAbstractOAuth::post(const QUrl &url, const QVariantMap ¶meters = QVariantMap())
[signal]
void QAbstractOAuth::replyDataReceived(const QByteArray &data)
QAbstractOAuthReplyHandler *QAbstractOAuth::replyHandler() const
Returns the reply handler currently in use.
参见 setReplyHandler() and QAbstractOAuthReplyHandler.
[signal]
void QAbstractOAuth::requestFailed(const 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.
参见 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.
Note: Setter function for property authorizationUrl.
参见 authorizationUrl().
[pure virtual]
void QAbstractOAuth::setClientIdentifier(const QString &clientIdentifier)
参见 clientIdentifier().
void QAbstractOAuth::setContentType(ContentType contentType)
Sets the current Content-Type to contentType.
Note: Setter function for property contentType.
参见 contentType().
void QAbstractOAuth::setModifyParametersFunction(const ModifyParametersFunction &modifyParametersFunction)
参见 modifyParametersFunction().
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.
参见 networkAccessManager() and QNetworkAccessManager.
void QAbstractOAuth::setReplyHandler(QAbstractOAuthReplyHandler *handler)
Sets the current reply handler to handler.
Note: Does not take ownership of handler.
参见 replyHandler().
[protected]
void QAbstractOAuth::setStatus(Status status)
Sets the current status to status. This method is for use by classes based on QAbstractOAuth.
参见 status().
[pure virtual]
void QAbstractOAuth::setToken(const QString &token)
参见 token().
Status QAbstractOAuth::status() const
Returns the current authentication status.
Note: Getter function for property status.
[pure virtual]
QString QAbstractOAuth::token() const
参见 setToken().