The QAbstractOAuth2 class is the base of all implementations of OAuth 2 authentication methods. 更多...
头: | #include <QAbstractOAuth2> |
CMake: |
find_package(Qt6 COMPONENTS NetworkAuth REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::NetworkAuth) |
qmake: | QT += networkauth |
Since: | Qt 5.8 |
继承: | QAbstractOAuth |
继承者: | QOAuth2AuthorizationCodeFlow |
|
QAbstractOAuth2 (QNetworkAccessManager * manager , QObject * parent = nullptr) | |
QAbstractOAuth2 (QObject * parent = nullptr) | |
virtual | ~QAbstractOAuth2 () |
QString | clientIdentifierSharedKey () const |
virtual QUrl | createAuthenticatedUrl (const QUrl & url , const QVariantMap & 参数 = QVariantMap()) |
QDateTime | expirationAt () const |
virtual QNetworkReply * | post (const QUrl & url , const QByteArray & data ) |
virtual QNetworkReply * | post (const QUrl & url , QHttpMultiPart * multiPart ) |
virtual QNetworkReply * | put (const QUrl & url , const QByteArray & data ) |
virtual QNetworkReply * | put (const QUrl & url , QHttpMultiPart * multiPart ) |
QString | refreshToken () const |
QString | responseType () const |
QString | scope () const |
void | setClientIdentifierSharedKey (const QString & clientIdentifierSharedKey ) |
void | setRefreshToken (const QString & refreshToken ) |
void | setScope (const QString & scope ) |
void | setState (const QString & state ) |
void | setUserAgent (const QString & userAgent ) |
QString | state () const |
QString | userAgent () const |
virtual QNetworkReply * | deleteResource (const QUrl & url , const QVariantMap & 参数 = QVariantMap()) override |
virtual QNetworkReply * | get (const QUrl & url , const QVariantMap & 参数 = QVariantMap()) override |
virtual QNetworkReply * | head (const QUrl & url , const QVariantMap & 参数 = QVariantMap()) override |
virtual QNetworkReply * | post (const QUrl & url , const QVariantMap & 参数 = QVariantMap()) override |
virtual void | prepareRequest (QNetworkRequest * request , const QByteArray & verb , const QByteArray & body = QByteArray()) override |
virtual QNetworkReply * | put (const QUrl & url , const QVariantMap & 参数 = QVariantMap()) override |
void | authorizationCallbackReceived (const QVariantMap & data ) |
void | clientIdentifierSharedKeyChanged (const QString & clientIdentifierSharedKey ) |
void | error (const QString & error , const QString & errorDescription , const QUrl & uri ) |
void | expirationAtChanged (const QDateTime & expiration ) |
void | refreshTokenChanged (const QString & refreshToken ) |
void | scopeChanged (const QString & scope ) |
void | stateChanged (const QString & state ) |
void | userAgentChanged (const QString & userAgent ) |
The class defines the basic interface of the OAuth 2 authentication classes. By inheriting this class, you can create custom authentication methods using the OAuth 2 standard for different web services.
A description of how OAuth 2 works can be found in: The OAuth 2.0 Authorization Framework
This property holds the client shared key used as a password if the server requires authentication to request the token.
访问函数:
QString | clientIdentifierSharedKey () const |
void | setClientIdentifierSharedKey (const QString & clientIdentifierSharedKey ) |
通知程序信号:
void | clientIdentifierSharedKeyChanged (const QString & clientIdentifierSharedKey ) |
[read-only]
expiration
: const
QDateTime
This property holds the expiration time of the current access token.
访问函数:
QDateTime | expirationAt () const |
通知程序信号:
void | expirationAtChanged (const QDateTime & expiration ) |
This property holds the desired scope which defines the permissions requested by the client.
访问函数:
QString | scope () const |
void | setScope (const QString & scope ) |
通知程序信号:
void | scopeChanged (const QString & scope ) |
This property holds the string sent to the server during authentication. The state is used to identify and validate the request when the callback is received.
访问函数:
QString | state () const |
void | setState (const QString & state ) |
通知程序信号:
void | stateChanged (const QString & state ) |
This property holds the User-Agent header used to create the network requests.
The default value is "QtOAuth/1.0 (+https://www.qt.io)".
访问函数:
QString | userAgent () const |
void | setUserAgent (const QString & userAgent ) |
通知程序信号:
void | userAgentChanged (const QString & userAgent ) |
Constructs a QAbstractOAuth2 object using parent as parent and sets manager as the network access manager.
Constructs a QAbstractOAuth2 object using parent 作为父级。
[signal]
void
QAbstractOAuth2::
authorizationCallbackReceived
(const
QVariantMap
&
data
)
Signal emitted when the reply server receives the authorization callback from the server: data contains the values received from the server.
[signal]
void
QAbstractOAuth2::
error
(const
QString
&
error
, const
QString
&
errorDescription
, const
QUrl
&
uri
)
Signal emitted when the server responds to the request with an error: error is the name of the error; errorDescription describes the error and uri is an optional URI containing more information about the error.
[虚拟]
QAbstractOAuth2::
~QAbstractOAuth2
()
销毁 QAbstractOAuth2 实例。
[virtual invokable]
QUrl
QAbstractOAuth2::
createAuthenticatedUrl
(const
QUrl
&
url
, const
QVariantMap
&
参数
= QVariantMap())
The returned URL is based on url , combining it with the given 参数 and the access token.
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
[override virtual invokable]
QNetworkReply
*QAbstractOAuth2::
deleteResource
(const
QUrl
&
url
, const
QVariantMap
&
参数
= QVariantMap())
重实现: QAbstractOAuth::deleteResource (const QUrl &url, const QVariantMap ¶meters).
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 .
[override virtual invokable]
QNetworkReply
*QAbstractOAuth2::
get
(const
QUrl
&
url
, const
QVariantMap
&
参数
= QVariantMap())
重实现: QAbstractOAuth::get (const QUrl &url, const QVariantMap ¶meters).
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 .
[override virtual invokable]
QNetworkReply
*QAbstractOAuth2::
head
(const
QUrl
&
url
, const
QVariantMap
&
参数
= QVariantMap())
重实现: QAbstractOAuth::head (const QUrl &url, const QVariantMap ¶meters).
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 .
[override virtual invokable]
QNetworkReply
*QAbstractOAuth2::
post
(const
QUrl
&
url
, const
QVariantMap
&
参数
= QVariantMap())
重实现: QAbstractOAuth::post (const QUrl &url, const QVariantMap ¶meters).
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 .
[virtual invokable, since 5.10]
QNetworkReply
*QAbstractOAuth2::
post
(const
QUrl
&
url
, const
QByteArray
&
data
)
这是重载函数。
Sends an authenticated POST request and returns a new QNetworkReply 。 url and data are used to create the request.
{Hypertext Transfer Protocol -- HTTP/1.1: POST}
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
该函数在 Qt 5.10 引入。
另请参阅 post () 和 https://tools.ietf.org/html/rfc2616#section-9.6 .
[virtual invokable, since 5.10]
QNetworkReply
*QAbstractOAuth2::
post
(const
QUrl
&
url
,
QHttpMultiPart
*
multiPart
)
这是重载函数。
Sends an authenticated POST request and returns a new QNetworkReply 。 url and multiPart are used to create the request.
{Hypertext Transfer Protocol -- HTTP/1.1: POST}
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
该函数在 Qt 5.10 引入。
另请参阅 post (), QHttpMultiPart ,和 https://tools.ietf.org/html/rfc2616#section-9.6 .
[override virtual]
void
QAbstractOAuth2::
prepareRequest
(
QNetworkRequest
*
request
, const
QByteArray
&
verb
, const
QByteArray
&
body
= QByteArray())
重实现: QAbstractOAuth::prepareRequest (QNetworkRequest *request, const QByteArray &verb, const QByteArray &body).
[override virtual invokable]
QNetworkReply
*QAbstractOAuth2::
put
(const
QUrl
&
url
, const
QVariantMap
&
参数
= QVariantMap())
重实现: QAbstractOAuth::put (const QUrl &url, const QVariantMap ¶meters).
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 .
[virtual invokable, since 5.10]
QNetworkReply
*QAbstractOAuth2::
put
(const
QUrl
&
url
, const
QByteArray
&
data
)
这是重载函数。
Sends an authenticated PUT request and returns a new QNetworkReply 。 url and data are used to create the request.
{Hypertext Transfer Protocol -- HTTP/1.1: PUT}
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
该函数在 Qt 5.10 引入。
另请参阅 put () 和 https://tools.ietf.org/html/rfc2616#section-9.6 .
[virtual invokable, since 5.10]
QNetworkReply
*QAbstractOAuth2::
put
(const
QUrl
&
url
,
QHttpMultiPart
*
multiPart
)
这是重载函数。
Sends an authenticated PUT request and returns a new QNetworkReply 。 url and multiPart are used to create the request.
{Hypertext Transfer Protocol -- HTTP/1.1: PUT}
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
该函数在 Qt 5.10 引入。
另请参阅 put (), QHttpMultiPart ,和 https://tools.ietf.org/html/rfc2616#section-9.6 .
Gets the current refresh token.
Refresh tokens usually have longer lifespans than access tokens, so it makes sense to save them for later use.
Returns the current refresh token or an empty string, if there is no refresh token available.
注意: Getter function for property refreshToken.
另请参阅 setRefreshToken ().
返回 response_type used.
Sets the new refresh token refreshToken to be used.
A custom refresh token can be used to refresh the access token via this method and then the access token can be refreshed via QOAuth2AuthorizationCodeFlow::refreshAccessToken ().
注意: setter 函数对于特性 refreshToken .
另请参阅 refreshToken ().