The QAbstractOAuth class is the base of all implementations of OAuth authentication methods. 更多...
头: | #include <QAbstractOAuth> |
CMake: |
find_package(Qt6 COMPONENTS NetworkAuth REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::NetworkAuth) |
qmake: | QT += networkauth |
Since: | Qt 5.8 |
继承: | QObject |
继承者: | QAbstractOAuth2 and QOAuth1 |
enum class | ContentType { WwwFormUrlEncoded, Json } |
enum class | Error { NoError, NetworkError, ServerError, OAuthTokenNotFoundError, OAuthTokenSecretNotFoundError, OAuthCallbackNotVerified } |
enum class | Stage { RequestingTemporaryCredentials, RequestingAuthorization, RequestingAccessToken, RefreshingAccessToken } |
enum class | 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 & 参数 = QVariantMap()) = 0 |
QVariantMap | extraTokens () const |
virtual QNetworkReply * | get (const QUrl & url , const QVariantMap & 参数 = QVariantMap()) = 0 |
virtual QNetworkReply * | head (const QUrl & url , const QVariantMap & 参数 = QVariantMap()) = 0 |
QAbstractOAuth::ModifyParametersFunction | modifyParametersFunction () const |
QNetworkAccessManager * | networkAccessManager () const |
virtual QNetworkReply * | post (const QUrl & url , const QVariantMap & 参数 = QVariantMap()) = 0 |
virtual void | prepareRequest (QNetworkRequest * request , const QByteArray & verb , const QByteArray & body = QByteArray()) = 0 |
virtual QNetworkReply * | put (const QUrl & url , const QVariantMap & 参数 = QVariantMap()) = 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 | granted () |
void | statusChanged (QAbstractOAuth::Status status ) |
void | tokenChanged (const QString & token ) |
QString | callback () const |
virtual void | resourceOwnerAuthorization (const QUrl & url , const QMultiMap<QString, QVariant> & 参数 ) |
void | setStatus (QAbstractOAuth::Status status ) |
QByteArray | generateRandomString (quint8 length ) |
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.
常量 | 值 | 描述 |
---|---|---|
QAbstractOAuth::ContentType::WwwFormUrlEncoded
|
0
|
Uses application/x-www-form-urlencoded format. |
QAbstractOAuth::ContentType::Json
|
1
|
Uses application/json format. |
Indicates the latest received error.
常量 | 值 | 描述 |
---|---|---|
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. |
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.
常量 | 值 | 描述 |
---|---|---|
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. |
Indicates the current authentication status.
常量 | 值 | 描述 |
---|---|---|
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. |
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 ) |
通知程序信号:
void | authorizationUrlChanged (const QUrl & url ) |
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.
访问函数:
QAbstractOAuth::ContentType | contentType () const |
void | setContentType (QAbstractOAuth::ContentType contentType ) |
通知程序信号:
void | contentTypeChanged (QAbstractOAuth::ContentType contentType ) |
[read-only]
extraTokens
: const
QVariantMap
This property holds the extra tokens received from the server.
访问函数:
QVariantMap | extraTokens () const |
通知程序信号:
void | extraTokensChanged (const QVariantMap & tokens ) |
[read-only]
status
: const
Status
This property holds the current authentication status.
访问函数:
QAbstractOAuth::Status | status () const |
通知程序信号:
void | statusChanged (QAbstractOAuth::Status status ) |
[signal]
void
QAbstractOAuth::
authorizeWithBrowser
(const
QUrl
&
url
)
此信号被发射当 url generated by resourceOwnerAuthorization () is ready to be used in the web browser to allow the application to impersonate the user.
另请参阅 resourceOwnerAuthorization ().
[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.
[虚拟]
QAbstractOAuth::
~QAbstractOAuth
()
Destroys the abstract OAuth.
Returns the authorization request URL.
注意: Getter function for property authorizationUrl.
另请参阅 setAuthorizationUrl ().
[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 () 和 setReplyHandler ().
Returns the current client identifier used in the authentication process.
注意: Getter function for property clientIdentifier.
另请参阅 setClientIdentifier ().
Returns the current Content-Type used in authenticated calls.
注意: Getter function for property contentType.
另请参阅 setContentType () 和 post ().
[pure virtual invokable]
QNetworkReply
*QAbstractOAuth::
deleteResource
(const
QUrl
&
url
, const
QVariantMap
&
参数
= QVariantMap())
Sends an authenticated DELETE request and returns a new QNetworkReply 。 url and 参数 are used to create the request.
另请参阅 : Hypertext Transfer Protocol -- HTTP/1.1: DELETE
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
Returns the extra tokens received from the server during authentication.
注意: Getter function for property extraTokens.
另请参阅 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.
另请参阅 : The OAuth 1.0 Protocol: Nonce and Timestamp .
[pure virtual invokable]
QNetworkReply
*QAbstractOAuth::
get
(const
QUrl
&
url
, const
QVariantMap
&
参数
= QVariantMap())
Sends an authenticated GET request and returns a new QNetworkReply 。 url and 参数 are used to create the request.
另请参阅 : Hypertext Transfer Protocol -- HTTP/1.1: GET
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
[pure virtual invokable]
QNetworkReply
*QAbstractOAuth::
head
(const
QUrl
&
url
, const
QVariantMap
&
参数
= QVariantMap())
Sends an authenticated HEAD request and returns a new QNetworkReply 。 url and 参数 are used to create the request.
另请参阅 : Hypertext Transfer Protocol -- HTTP/1.1: HEAD
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
Returns the current parameter-modification function.
另请参阅 setModifyParametersFunction () 和 Stage .
Returns the current network access manager used to send the requests to the server during authentication flows or to make authentication calls.
另请参阅 setNetworkAccessManager () 和 QNetworkAccessManager .
[pure virtual invokable]
QNetworkReply
*QAbstractOAuth::
post
(const
QUrl
&
url
, const
QVariantMap
&
参数
= QVariantMap())
Sends an authenticated POST request and returns a new QNetworkReply 。 url and 参数 are used to create the request.
另请参阅 : Hypertext Transfer Protocol -- HTTP/1.1: POST
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
[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.
verb must be a valid HTTP verb and the same as the one that will be used to send the request .
该函数在 Qt 5.13 引入。
[pure virtual invokable]
QNetworkReply
*QAbstractOAuth::
put
(const
QUrl
&
url
, const
QVariantMap
&
参数
= QVariantMap())
Sends an authenticated PUT request and returns a new QNetworkReply 。 url and 参数 are used to create the request.
另请参阅 : Hypertext Transfer Protocol -- HTTP/1.1: PUT
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
Returns the reply handler currently in use.
另请参阅 setReplyHandler () 和 QAbstractOAuthReplyHandler .
[virtual protected]
void
QAbstractOAuth::
resourceOwnerAuthorization
(const
QUrl
&
url
, const
QMultiMap
<
QString
,
QVariant
> &
参数
)
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 参数 . When the URL is ready, the authorizeWithBrowser () signal will be emitted with the generated URL.
另请参阅 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.
注意: setter 函数对于特性 authorizationUrl .
另请参阅 authorizationUrl ().
Sets the current client identifier to clientIdentifier .
注意: setter 函数对于特性 clientIdentifier .
另请参阅 clientIdentifier ().
Sets the current Content-Type to contentType .
注意: setter 函数对于特性 contentType .
另请参阅 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.
另请参阅 modifyParametersFunction () 和 Stage .
将网络管理器设为 networkAccessManager . QAbstractOAuth 未拥有所有权对于 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 () 和 QNetworkAccessManager .
Sets the current reply handler to handler .
注意: Does not take ownership of handler .
另请参阅 replyHandler ().
[protected]
void
QAbstractOAuth::
setStatus
(
QAbstractOAuth::Status
status
)
Sets the current status to status . This method is for use by classes based on QAbstractOAuth .
另请参阅 status ().
Sets the token used to sign authenticated requests to token .
注意: setter 函数对于特性 token .
另请参阅 token ().
Returns the current authentication status.
注意: getter 函数对于特性 status。
Returns the token used to sign the authenticated requests.
注意: Getter function for property token.
另请参阅 setToken ().