The QOAuth2AuthorizationCodeFlow class provides an implementation of the Authorization Code Grant flow. 更多...
| 頭: |
#include <QOAuth2AuthorizationCodeFlow>
|
| CMake: |
find_package(Qt6 REQUIRED COMPONENTS NetworkAuth)
target_link_libraries(mytarget PRIVATE Qt6::NetworkAuth)
|
| qmake: |
QT += networkauth
|
| 繼承: | QAbstractOAuth2 |
(從 6.8 起)
枚舉類
|
PkceMethod { None, Plain, S256 } |
| QOAuth2AuthorizationCodeFlow (QObject * parent = nullptr) | |
| QOAuth2AuthorizationCodeFlow (QNetworkAccessManager * manager , QObject * parent = nullptr) | |
| QOAuth2AuthorizationCodeFlow (const QString & clientIdentifier , QNetworkAccessManager * manager , QObject * parent = nullptr) | |
| QOAuth2AuthorizationCodeFlow (const QUrl & authenticateUrl , const QUrl & accessTokenUrl , QNetworkAccessManager * manager , QObject * parent = nullptr) | |
| QOAuth2AuthorizationCodeFlow (const QString & clientIdentifier , const QUrl & authenticateUrl , const QUrl & accessTokenUrl , QNetworkAccessManager * manager , QObject * parent = nullptr) | |
| virtual | ~QOAuth2AuthorizationCodeFlow () |
| QUrl | accessTokenUrl () const |
(從 6.8 起)
QOAuth2AuthorizationCodeFlow::PkceMethod
|
pkceMethod () const |
| void | setAccessTokenUrl (const QUrl & accessTokenUrl ) |
(從 6.8 起)
void
|
setPkceMethod (QOAuth2AuthorizationCodeFlow::PkceMethod method , qsizetype length = 43) |
| virtual void | grant () override |
| void | refreshAccessToken () |
| void | accessTokenUrlChanged (const QUrl & accessTokenUrl ) |
| QUrl | buildAuthenticateUrl (const QMultiMap<QString, QVariant> & 參數 = {}) |
| void | requestAccessToken (const QString & code ) |
| virtual void | resourceOwnerAuthorization (const QUrl & url , const QMultiMap<QString, QVariant> & 參數 = {}) override |
This class implements the Authorization Code Grant flow, which is used both to obtain and to refresh access tokens. It is a redirection-based flow so the user will need access to a web browser.
As a redirection-based flow this class requires a proper reply handler to be set. See Qt OAuth2 概述 , QOAuthHttpServerReplyHandler ,和 QOAuthUriSchemeReplyHandler .
[since 6.8]
enum class QOAuth2AuthorizationCodeFlow::
PkceMethod
List of available Proof Key for Code Exchange (PKCE) methods .
PKCE is a security measure to mitigate the risk of authorization code interception attacks . As such it is relevant for OAuth2 "Authorization Code" flow (grant) and in particular with native applications.
PKCE inserts additional parameters into authorization and access token requests. With the help of these parameters the authorization server is able to verify that an access token request originates from the same entity that issued the authorization request.
| 常量 | 值 | 描述 |
|---|---|---|
QOAuth2AuthorizationCodeFlow::PkceMethod::None
|
255
|
PKCE is not used. |
QOAuth2AuthorizationCodeFlow::PkceMethod::Plain
|
1
|
The Plain PKCE method is used. Use this only if it is not possible to use S256. With Plain method the code challenge equals to the code verifier . |
QOAuth2AuthorizationCodeFlow::PkceMethod::S256
|
0
|
The S256 PKCE method is used. This is the default and the recommended method for native applications. With the S256 method the code challenge is a base64url-encoded value of the SHA-256 of the code verifier . |
該枚舉在 Qt 6.8 引入。
另請參閱 setPkceMethod () 和 pkceMethod ().
This property holds the URL used to convert the temporary code received during the authorization response.
另請參閱 : Access Token Request
訪問函數:
| QUrl | accessTokenUrl () const |
| void | setAccessTokenUrl (const QUrl & accessTokenUrl ) |
通知程序信號:
| void | accessTokenUrlChanged (const QUrl & accessTokenUrl ) |
[explicit]
QOAuth2AuthorizationCodeFlow::
QOAuth2AuthorizationCodeFlow
(
QObject
*
parent
= nullptr)
Constructs a QOAuth2AuthorizationCodeFlow object with parent object parent .
[explicit]
QOAuth2AuthorizationCodeFlow::
QOAuth2AuthorizationCodeFlow
(
QNetworkAccessManager
*
manager
,
QObject
*
parent
= nullptr)
Constructs a QOAuth2AuthorizationCodeFlow object using parent as parent and sets manager as the network access manager.
Constructs a QOAuth2AuthorizationCodeFlow object using parent as parent and sets manager as the network access manager. The client identifier is set to clientIdentifier .
Constructs a QOAuth2AuthorizationCodeFlow object using parent as parent and sets manager as the network access manager. The authenticate URL is set to authenticateUrl and the access token URL is set to accessTokenUrl .
Constructs a QOAuth2AuthorizationCodeFlow object using parent as parent and sets manager as the network access manager. The client identifier is set to clientIdentifier the authenticate URL is set to authenticateUrl and the access token URL is set to accessTokenUrl .
[virtual noexcept]
QOAuth2AuthorizationCodeFlow::
~QOAuth2AuthorizationCodeFlow
()
銷毀 QOAuth2AuthorizationCodeFlow 實例。
Returns the URL used to request the access token.
注意: Getter function for property accessTokenUrl.
另請參閱 setAccessTokenUrl ().
[protected]
QUrl
QOAuth2AuthorizationCodeFlow::
buildAuthenticateUrl
(const
QMultiMap
<
QString
,
QVariant
> &
參數
= {})
Generates an authentication URL to be used in the Authorization Request 使用 parameters .
[override virtual slot]
void
QOAuth2AuthorizationCodeFlow::
grant
()
重實現: QAbstractOAuth::grant ().
Starts the authentication flow as described in The OAuth 2.0 Authorization Framework
[noexcept, since 6.8]
QOAuth2AuthorizationCodeFlow::PkceMethod
QOAuth2AuthorizationCodeFlow::
pkceMethod
() const
Returns the current PKCE method.
該函數在 Qt 6.8 引入。
另請參閱 setPkceMethod () 和 QOAuth2AuthorizationCodeFlow::PkceMethod .
[slot]
void
QOAuth2AuthorizationCodeFlow::
refreshAccessToken
()
Call this function to refresh the token. Access tokens are not permanent. After a time specified along with the access token when it was obtained, the access token will become invalid.
If refreshing the token fails and an access token exists, the status is set to QAbstractOAuth::Status::Granted , and to QAbstractOAuth::Status::NotAuthenticated 否則。
另請參閱 QAbstractOAuth::requestFailed () 和 Refresh Token .
[protected]
void
QOAuth2AuthorizationCodeFlow::
requestAccessToken
(const
QString
&
code
)
Requests an access token from the received code 。 code is received as a response when the user completes a successful authentication in the browser.
[override virtual protected]
void
QOAuth2AuthorizationCodeFlow::
resourceOwnerAuthorization
(const
QUrl
&
url
, const
QMultiMap
<
QString
,
QVariant
> &
參數
= {})
重實現: QAbstractOAuth::resourceOwnerAuthorization (const QUrl &url, const QMultiMap<QString, QVariant> ¶meters).
Builds an authentication URL using url and parameters . This function emits an authorizeWithBrowser () signal to require user interaction.
Sets the URL used to request the access token to accessTokenUrl .
注意: setter 函數對於特性 accessTokenUrl .
另請參閱 accessTokenUrl ().
[since 6.8]
void
QOAuth2AuthorizationCodeFlow::
setPkceMethod
(
QOAuth2AuthorizationCodeFlow::PkceMethod
method
,
qsizetype
length
= 43)
Sets the current PKCE method to method .
Optionally, the
length
parameter can be used to set the length of the
code_verifier
. The value must be between 43 and 128 bytes. The 'code verifier' itself is random-generated by the library.
該函數在 Qt 6.8 引入。
另請參閱 pkceMethod () 和 QOAuth2AuthorizationCodeFlow::PkceMethod .