QAbstractOAuth2 Class

The QAbstractOAuth2 class is the base of all implementations of OAuth 2 authentication methods. 更多...

頭: #include <QAbstractOAuth2>
CMake: find_package(Qt6 REQUIRED COMPONENTS NetworkAuth)
target_link_libraries(mytarget PRIVATE Qt6::NetworkAuth)
qmake: QT += networkauth
繼承: QAbstractOAuth
繼承者:

QOAuth2AuthorizationCodeFlow

特性

公共函數

QAbstractOAuth2 (QObject * parent = nullptr)
QAbstractOAuth2 (QNetworkAccessManager * manager , QObject * parent = nullptr)
virtual ~QAbstractOAuth2 ()
QString clientIdentifierSharedKey () const
virtual QUrl createAuthenticatedUrl (const QUrl & url , const QVariantMap & 參數 = QVariantMap())
QDateTime expirationAt () const
(until 6.11) virtual QNetworkReply * post (const QUrl & url , QHttpMultiPart * multiPart )
(until 6.11) virtual QNetworkReply * post (const QUrl & url , const QByteArray & data )
(until 6.11) virtual QNetworkReply * put (const QUrl & url , QHttpMultiPart * multiPart )
(until 6.11) virtual QNetworkReply * put (const QUrl & url , const QByteArray & data )
QString refreshToken () const
QString responseType () const
QString scope () const
void setClientIdentifierSharedKey (const QString & clientIdentifierSharedKey )
void setRefreshToken (const QString & refreshToken )
void setScope (const QString & scope )
(從 6.5 起) void setSslConfiguration (const QSslConfiguration & configuration )
void setState (const QString & state )
void setUserAgent (const QString & userAgent )
(從 6.5 起) QSslConfiguration sslConfiguration () const
QString state () const
QString userAgent () const

重實現公共函數

(until 6.11) virtual QNetworkReply * deleteResource (const QUrl & url , const QVariantMap & 參數 = QVariantMap()) override
(until 6.11) virtual QNetworkReply * get (const QUrl & url , const QVariantMap & 參數 = QVariantMap()) override
(until 6.11) virtual QNetworkReply * head (const QUrl & url , const QVariantMap & 參數 = QVariantMap()) override
(until 6.11) virtual QNetworkReply * post (const QUrl & url , const QVariantMap & 參數 = QVariantMap()) override
virtual void prepareRequest (QNetworkRequest * request , const QByteArray & verb , const QByteArray & body = QByteArray()) override
(until 6.11) 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 )
(從 6.5 起) void sslConfigurationChanged (const QSslConfiguration & configuration )
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

特性文檔編製

clientIdentifierSharedKey : QString

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. An invalid value means that the authorization server hasn't provided a valid expiration time.

訪問函數:

QDateTime expirationAt () const

通知程序信號:

void expirationAtChanged (const QDateTime & expiration )

另請參閱 QDateTime::isValid ().

scope : QString

This property holds the desired scope which defines the permissions requested by the client.

The scope value is updated to the scope value granted by the authorization server. In case of an empty scope response, the requested scope is assumed as granted and does not change .

訪問函數:

QString scope () const
void setScope (const QString & scope )

通知程序信號:

void scopeChanged (const QString & scope )

state : QString

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 )

userAgent : QString

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 )

成員函數文檔編製

[explicit] QAbstractOAuth2:: QAbstractOAuth2 ( QObject * parent = nullptr)

Constructs a QAbstractOAuth2 object using parent 作為父級。

[explicit] QAbstractOAuth2:: QAbstractOAuth2 ( QNetworkAccessManager * manager , QObject * parent = nullptr)

Constructs a QAbstractOAuth2 object using parent as parent and sets manager as the network access manager.

[virtual noexcept] QAbstractOAuth2:: ~QAbstractOAuth2 ()

銷毀 QAbstractOAuth2 實例。

[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.

[virtual invokable] QUrl QAbstractOAuth2:: createAuthenticatedUrl (const QUrl & url , const QVariantMap & 參數 = QVariantMap())

The returned URL is based on url , combining it with the given parameters and the access token.

注意: 此函數可以被援引,通過元對象係統和從 QML。見 Q_INVOKABLE .

[override virtual invokable, until 6.11] QNetworkReply *QAbstractOAuth2:: deleteResource (const QUrl & url , const QVariantMap & 參數 = QVariantMap())

This function is scheduled for deprecation in version 6.11.

重實現: QAbstractOAuth::deleteResource (const QUrl &url, const QVariantMap ¶meters).

Please use QtNetwork classes directly instead, see HTTP method alternatives .

Sends an authenticated DELETE request and returns a new QNetworkReply url and parameters are used to create the request.

另請參閱 : Hypertext Transfer Protocol – HTTP/1.1: DELETE

注意: 此函數可以被援引,通過元對象係統和從 QML。見 Q_INVOKABLE .

[signal] void QAbstractOAuth2:: error (const QString & error , const QString & errorDescription , const QUrl & uri )

Signal emitted when the server responds to the authorization request with an error as defined in RFC 6749 error response .

error is the name of the error; errorDescription describes the error and uri is an optional URI containing more information about the error.

另請參閱 QAbstractOAuth::requestFailed ().

[override virtual invokable, until 6.11] QNetworkReply *QAbstractOAuth2:: get (const QUrl & url , const QVariantMap & 參數 = QVariantMap())

This function is scheduled for deprecation in version 6.11.

重實現: QAbstractOAuth::get (const QUrl &url, const QVariantMap ¶meters).

Please use QtNetwork classes directly instead, see HTTP method alternatives .

Sends an authenticated GET request and returns a new QNetworkReply url and parameters are used to create the request.

另請參閱 : Hypertext Transfer Protocol – HTTP/1.1: GET

注意: 此函數可以被援引,通過元對象係統和從 QML。見 Q_INVOKABLE .

This function is scheduled for deprecation in version 6.11.

重實現: QAbstractOAuth::head (const QUrl &url, const QVariantMap ¶meters).

Please use QtNetwork classes directly instead, see HTTP method alternatives .

Sends an authenticated HEAD request and returns a new QNetworkReply url and parameters are used to create the request.

另請參閱 : Hypertext Transfer Protocol – HTTP/1.1: HEAD

注意: 此函數可以被援引,通過元對象係統和從 QML。見 Q_INVOKABLE .

[override virtual invokable, until 6.11] QNetworkReply *QAbstractOAuth2:: post (const QUrl & url , const QVariantMap & 參數 = QVariantMap())

This function is scheduled for deprecation in version 6.11.

重實現: QAbstractOAuth::post (const QUrl &url, const QVariantMap ¶meters).

Please use QtNetwork classes directly instead, see HTTP method alternatives .

Sends an authenticated POST request and returns a new QNetworkReply url and parameters are used to create the request.

另請參閱 : Hypertext Transfer Protocol – HTTP/1.1: POST

注意: 此函數可以被援引,通過元對象係統和從 QML。見 Q_INVOKABLE .

[virtual invokable, until 6.11] QNetworkReply *QAbstractOAuth2:: post (const QUrl & url , QHttpMultiPart * multiPart )

This function is scheduled for deprecation in version 6.11.

Please use QtNetwork classes directly instead, see HTTP method alternatives .

這是重載函數。

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 .

另請參閱 post (), QHttpMultiPart ,和 https://tools.ietf.org/html/rfc2616#section-9.6 .

[virtual invokable, until 6.11] QNetworkReply *QAbstractOAuth2:: post (const QUrl & url , const QByteArray & data )

This function is scheduled for deprecation in version 6.11.

Please use QtNetwork classes directly instead, see HTTP method alternatives .

這是重載函數。

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 .

另請參閱 post () 和 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, until 6.11] QNetworkReply *QAbstractOAuth2:: put (const QUrl & url , const QVariantMap & 參數 = QVariantMap())

This function is scheduled for deprecation in version 6.11.

重實現: QAbstractOAuth::put (const QUrl &url, const QVariantMap ¶meters).

Please use QtNetwork classes directly instead, see HTTP method alternatives .

Sends an authenticated PUT request and returns a new QNetworkReply url and parameters are used to create the request.

另請參閱 : Hypertext Transfer Protocol – HTTP/1.1: PUT

注意: 此函數可以被援引,通過元對象係統和從 QML。見 Q_INVOKABLE .

[virtual invokable, until 6.11] QNetworkReply *QAbstractOAuth2:: put (const QUrl & url , QHttpMultiPart * multiPart )

This function is scheduled for deprecation in version 6.11.

Please use QtNetwork classes directly instead, see HTTP method alternatives .

這是重載函數。

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 .

另請參閱 put (), QHttpMultiPart ,和 https://tools.ietf.org/html/rfc2616#section-9.6 .

[virtual invokable, until 6.11] QNetworkReply *QAbstractOAuth2:: put (const QUrl & url , const QByteArray & data )

This function is scheduled for deprecation in version 6.11.

Please use QtNetwork classes directly instead, see HTTP method alternatives .

這是重載函數。

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 .

另請參閱 put () 和 https://tools.ietf.org/html/rfc2616#section-9.6 .

QString QAbstractOAuth2:: refreshToken () const

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 ().

QString QAbstractOAuth2:: responseType () const

返迴 response_type used.

void QAbstractOAuth2:: setRefreshToken (const QString & refreshToken )

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 ().

[since 6.5] void QAbstractOAuth2:: setSslConfiguration (const QSslConfiguration & configuration )

Sets the TLS configuration to be used when establishing a mutual TLS connection between the client and the Authorization Server.

該函數在 Qt 6.5 引入。

另請參閱 sslConfiguration () 和 sslConfigurationChanged ().

[since 6.5] QSslConfiguration QAbstractOAuth2:: sslConfiguration () const

Returns the TLS configuration to be used when establishing a mutual TLS connection between the client and the Authorization Server.

該函數在 Qt 6.5 引入。

另請參閱 setSslConfiguration () 和 sslConfigurationChanged ().

[signal, since 6.5] void QAbstractOAuth2:: sslConfigurationChanged (const QSslConfiguration & configuration )

The signal is emitted when the TLS configuration has changed. The configuration parameter contains the new TLS configuration.

該函數在 Qt 6.5 引入。

另請參閱 sslConfiguration () 和 setSslConfiguration ().