summaryrefslogtreecommitdiffstats
path: root/tests
Commit message (Collapse)AuthorAgeFilesLines
* Mark the whole repo with QT_NO_URL_CAST_FROM_STRINGAhmad Samir6 days4-25/+25
| | | | | | Pick-to: 6.11 Change-Id: I8bd4e61bcbd957defb117ef16189033c903efcd0 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Add QT_NO_SSL guard to autotest function declarationJuha Vuolle2025-02-201-0/+2
| | | | | | | | | | | | To match with the function definition. Otherwise there is a linker error when compiling without SSL. Amends: 164e2d897fb7c3a60b518985774a4faa360ba2c9 Task-number: QTBUG-133928 Pick-to: 6.9 Change-Id: I69bf79312db93443725a26df35d2181101d54c9c Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Add qtcpsocketh.h includeJuha Vuolle2025-02-201-0/+1
| | | | | | | | | | | | | | Add qtcpsocket.h include as it's used by the header-only implementation. On most builds it's included indirectly through qsslconfiguration.h, but since it's inclusion is guarded with QT_NO_SSL, the code fails to compile when it's not defined. Amends: d1c168f97c91e0a7666ff397efe66bd7879e6720 Task-number: QTBUG-133928 Pick-to: 6.9 Change-Id: I5f9a8df56fcce01b9503070e3787f752a7574ab7 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Simplify and move scopeAndRequestedScope() test to tst_abstractoauth2Juha Vuolle2025-01-312-84/+62
| | | | | | | | | | | | | | Simplify the testcase by removing the checking of generated authorization code flow URLs. Testing that is more naturally covered by the scope() and requestedScopeTokens() testcases. The simplified case tests purely QAbstractOAuth2 properties and doesn't need the concrete actual flows. Pick-to: 6.9 Task-number: QTBUG-131922 Change-Id: I21c9d6f7466297c2da7cdcafa1cdf94120ab5682 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Remove unused variables in setInvalidScope() autotestJuha Vuolle2025-01-311-2/+0
| | | | | | | | Amends: 5c5fed1dc05b001eb75d9b7a5710df0e8e1941b2 Pick-to: 6.9 Change-Id: Iac564ba6a8c077a447240839d6d78867036cf69c Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Move scopeCharacterWarnings() autotest to tst_abstractoauth2Juha Vuolle2025-01-302-52/+52
| | | | | | | | | | Tests purely QAbstractOAuth2 properties and doesn't need the concrete actual flows. Pick-to: 6.9 Task-number: QTBUG-131922 Change-Id: I3d3b806745f59de4a2510aec36e3e5afac775eed Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Move setInvalidScope() autotest to tst_abstractoauth2Juha Vuolle2025-01-302-53/+59
| | | | | | | | | | Tests purely QAbstractOAuth2 properties and doesn't need the concrete actual flows. Pick-to: 6.9 Task-number: QTBUG-131922 Change-Id: Ie6c3a0b519082c6a608a380a5ed6ef001b1b02d1 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Add testcase for different token response content formatsJuha Vuolle2025-01-301-0/+73
| | | | | | | | Basically just to add test coverage. Pick-to: 6.9 6.8 Change-Id: I4fed6054c369e1ee4f5c8692b7e1645341dafb3a Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Rename networkReplyErrors() testcase to tokenReplyErrors()Juha Vuolle2025-01-301-4/+4
| | | | | | | | | | This better captures what the test is about. Amends: 08f30372a7d3a08d566be5598ac4a37f564f0aeb Pick-to: 6.9 6.8 Change-Id: I4ea60c1b50fc5101555ea51fe5662742a4e802d8 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Make tst_oauth2codeflow to use shared authorization serverJuha Vuolle2025-01-301-150/+113
| | | | | | | | | | | | | | | | In addition to fostering reuse and familiarity with other test cases, this allows hiding the "HTTP details" which are not the focus of these tests. Note: commit modifies the test's reply handler to ingest JSON objects instead of url-encoded data. This is just an autotest detail since the test reply handler is not a real handler. Pick-to: 6.9 Task-number: QTBUG-131922 Change-Id: I604078544130b55ca6680f5b577a076dfda05eb7 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Make tst_oauth2deviceflow to use shared authorization serverJuha Vuolle2025-01-301-305/+206
| | | | | | | | | | | | The static constexpr responses are now const QByteArrays for performance reasons. They are used repeatedly, and by using const QBAs they'll incur instantiation cost once at startup (as opposed to each time they are used). Pick-to: 6.9 Task-number: QTBUG-131922 Change-Id: Ie45be1ff3b7b7c1e7068036a315d7c8a0faca061 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Introduce shared autotest authorization serverJuha Vuolle2025-01-301-0/+74
| | | | | | | | | | | | | | Authorization server in shared testutils allows using the same authorization server across test cases. This implementation originates from tst_oauth2deviceflow testcase with some modifications. Followup patch removes the original authorization server and starts using the one introduced here. Pick-to: 6.9 Task-number: QTBUG-131922 Change-Id: I2ec180bbe58a88db14d79031e9616cd430d7c462 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Move prepareRequest() to tst_abstractoauth2Juha Vuolle2025-01-302-11/+11
| | | | | | | | | | | This is a step towards clarifying the scope of QAbstractOAuth2, QOAuth2AuthorizationCodeFlow, and QOAuth2DeviceAuthorizationFlow autotests. Pick-to: 6.9 Task-number: QTBUG-131922 Change-Id: I27e41dc7a319c614904f48e8727fc18d91478bfd Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Move nonce() common parts to tst_abstractoauth2.cppJuha Vuolle2025-01-303-58/+36
| | | | | | | | | | | This is a step towards clarifying the scope of QAbstractOAuth2, QOAuth2AuthorizationCodeFlow, and QOAuth2DeviceAuthorizationFlow autotests. Pick-to: 6.9 Task-number: QTBUG-131922 Change-Id: Ic4d753208a522371f3231b53335705f6a05bfd8c Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Move sslConfig() and invalidLeadTime() to tst_abstractoauth2Juha Vuolle2025-01-303-38/+60
| | | | | | | | | | | This is a step towards clarifying the scope of QAbstractOAuth2, QOAuth2AuthorizationCodeFlow, and QOAuth2DeviceAuthorizationFlow autotests. Pick-to: 6.9 Task-number: QTBUG-131922 Change-Id: Ie4b8e862c6cdc8b73b5e67c021a82e4c4cb4eb3a Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Move autoRefresh(), and tokenUrl() common parts into tst_abstractoauth2Juha Vuolle2025-01-303-61/+78
| | | | | | | | | | | This is a step towards clarifying the scope of QAbstractOAuth2, QOAuth2AuthorizationCodeFlow, and QOAuth2DeviceAuthorizationFlow autotests. Pick-to: 6.9 Task-number: QTBUG-131922 Change-Id: I91006d460e99308258b6c13ef5eeee86227d1beb Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Add dedicated autotest for QAbstractOAuth2Juha Vuolle2025-01-303-0/+32
| | | | | | | | | | | This is a step towards clarifying the scope of QAbstractOAuth2, QOAuth2AuthorizationCodeFlow, and QOAuth2DeviceAuthorizationFlow autotests. Pick-to: 6.9 Task-number: QTBUG-131922 Change-Id: I53208f9ece2b04ccc95a527b4918a77fc3140066 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Rename tst_oauth2 test to tst_oauth2codeflowJuha Vuolle2025-01-303-48/+39
| | | | | | | | | | | This is a step towards clarifying the scope of QAbstractOAuth2, QOAuth2AuthorizationCodeFlow, and QOAuth2DeviceAuthorizationFlow autotests. Pick-to: 6.9 Task-number: QTBUG-131922 Change-Id: Idd84e80125aee4c666cdfd00012b2133941df416 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Make webserver and tlswebserver autotest utilities not a header-onlyJuha Vuolle2025-01-308-300/+332
| | | | | | | | | | Cleaner and more readable this way. As a drive-by, change include style to more conventional style Pick-to: 6.9 Task-number: QTBUG-131922 Change-Id: I35fa8f28240bf7b4c96ecc3c89d19556411f4d96 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Make oauthtestutils not a header-onlyJuha Vuolle2025-01-304-64/+85
| | | | | | | | | | | | That way it's cleaner as an API (likely to grow over time). 'useTemporaryKeychain' is kept as a header implementation due to the 'auto' return value (compiler needs to see the definition at compile time to deduce the type). Pick-to: 6.9 Change-Id: I3b32d098d0bc1588d3b9c5a1fc69e91c243e3078 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QAbstractOAuth2: reject invalid scope-tokens in setRequestedScopeTokens()Marc Mutz2025-01-281-2/+14
| | | | | | | | | | | The old property, scope, continues to support such tokens as it did in Qt 6.8, but the new property rejects them now. This is a way to figure out whether users need this functionality or we can start to enforce RFC-compliance going forward. Pick-to: 6.9 Change-Id: Id90a84d7ac15eaea5cb8d8b8d12a3b0ab1b32ad8 Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
* QAbstractOAuth2: split the warning function according to encodingMarc Mutz2025-01-271-0/+53
| | | | | | | | | | | | | | | | We have two ways in which invalid scope-token characters can enter: First, in UTF-16 form, via the legacy `scope` property, or, decoded from UTF-8, as the server's answer. Second, in octet-stream form, using the new requestedScopeTokens property. The handling of both need to be different, in particular, the validation needs to happen in the original encoding (UTF-16 for the first, std::byte in the second), so split the warning code into two, one for each encoding. Pick-to: 6.9 Change-Id: I49752a49b531deacbba74e149e6620a68b25d57a Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
* Add QOAUTH2_NO_LEGACY_SCOPEMarc Mutz2025-01-241-5/+5
| | | | | | | | | | | | | | DRYs the many repetitions of the QT_REMOVAL_QT7_DEPRECATED_SINCE(6,13) and incidentally shows that the QOAuth2AuthorizationCodeFlow::accessTokenUrl property seems to have inconsistent deprecation macros, because the QT_REMOVAL_QT7_DEPRECATED_SINCE(6,13) around its \property qdoc block is now the only remaining QT_REMOVAL_QT7_DEPRECATED_SINCE(6, 13) in the module... Pick-to: 6.9 Change-Id: I30c5dd12b696c4ade206a7058498bb0399c0c261 Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
* Issue a warning on invalid scope tokensJuha Vuolle2025-01-241-0/+40
| | | | | | | | | | | | Resulted from API-review. Amends: 571b71763c0485778623139359acc88985099efb Task-number: QTBUG-132710 Pick-to: 6.9 Change-Id: I900e78b28be37bc83245a3f4247fc6613b061092 Reviewed-by: Juha Vuolle <juha.vuolle@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Change '*scopeTokens' type from QStringList to QSet<QByteArray>Juha Vuolle2025-01-242-88/+100
| | | | | | | | | | | | | | | | | This better reflects the scope (token) semantics: - Token order doesn't matter - Duplicate tokens don't make sense - Character encoding is limited to ASCII (albeit there might be proprietary authorization servers not adhering to this) Resulted from API-review. Amends: 571b71763c0485778623139359acc88985099efb Task-number: QTBUG-132710 Pick-to: 6.9 Change-Id: I781a707fcb3e2f06309e7ea57c5b05203afce03a Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Rename 'requestedScope' and 'grantedScope' to '*ScopeTokens'Juha Vuolle2025-01-232-74/+77
| | | | | | | | | | | | | | This commit is a prequel commit for changing their type from QStringList to QSet<QByteArray>, each member of the set representing a scope token. Resulted from API-review. Amends: 571b71763c0485778623139359acc88985099efb Task-number: QTBUG-132710 Pick-to: 6.9 Change-Id: I9d97ddfb66caba13434a460e021356911ed72f6c Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QOAuth2DeviceAuthorizationFlow: prepare for a unique_ptr QObject::d_ptrMarc Mutz2025-01-171-1/+1
| | | | | | | | | | Use only the std-compatible subset of smart pointer APIs. Pick-to: 6.9 Task-number: QTBUG-132213 Change-Id: I84cb9eb8ee456a4543ec1b5ed384a5e3aae04f13 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
* Do not remove accessTokenUrl() tests in Qt 7Ivan Solovev2025-01-162-6/+14
| | | | | | | | | | | | The property is no longer scheduled for removal in Qt 7, so we should change the guards that we use around the calls in the tests, otherwise the tests will be automatically removed in Qt 7. Amends c14c6db0df256acafd8e1f0dda185f27510f11e6 Pick-to: 6.9 Change-Id: Ic7f82f0bb97535b4fd5cfd2e73000a221a2c0dd3 Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
* Make refreshAccessToken() a regular deprecation without Qt 7 removalJuha Vuolle2025-01-161-1/+3
| | | | | | | | | | | | | | | Qt 6.9 introduces common baseclass method, refreshTokens() whose implementation can be overridden by classes. Marking the refreshAccessToken() as deprecated, and not automatically removing it, is adequate and minimizes user impact. Found in API review. Amends 2b1e3419c5ef43e964f40dbe79d7a7da0de5aa57 Pick-to: 6.9 Change-Id: I67fa85a4225500d5fc0fcb882e3fc90a5c63913f Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Use refreshTokens() as an NVI already in Qt 6Juha Vuolle2025-01-162-28/+20
| | | | | | | | | | | | | | | | | | | | | | | | | This allows having a common baseclass method for refreshing tokens already in Qt 6. This should minimize the user impact of removing the leaf class "refreshAccessToken()" function in Qt 7. Furthermore this simplifies the automatic token refresh implementation, which is implemented at the common baseclass level; the implementation can inokve/call the refreshTokens() directly, as opposed to the leaf class connecting to the accessTokenAboutToExpire() signal. Lastly this allows removing the (new in Qt 6.9) "QOAuth2DeviceAuthorizationFlow::refresAccessTokens()" function which would have been replaced in Qt 7. Found in API review. Amends 2b1e3419c5ef43e964f40dbe79d7a7da0de5aa57 Pick-to: 6.9 Change-Id: I3ad94486543bdcb5ef5a7afd41f9cbb249ac92fb Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Fix TLS authentication tests on WindowsIvan Solovev2025-01-142-2/+8
| | | | | | | | | | | | | | | | | | On both my Windows machines the tests always reports all three expected errors, but the CI seems to be ok with the old version of the test. This might be related to schannel vs openssl backend implementation, so use QCOMPARE_GE() to make both of them happy. Also add a QCOMPARE_LE() check to make sure that we do not get too many errors. We anyway verify that we get only the expected errors later on, so this shouldn't break any tests. Amends db2f209b2d299def846503e632dc9999e3007cba and 164e2d897fb7c3a60b518985774a4faa360ba2c9. Pick-to: 6.9 6.8 6.5 Change-Id: I16c5d442b9ddc62dae3e3a22d0b7327661521d80 Reviewed-by: Juha Vuolle <juha.vuolle@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Skip tst_OAuth2DeviceFlow::tlsAuthentication on macOS 15Tor Arne Vestbø2024-12-191-0/+14
| | | | | | Pick-to: 6.9 6.8 Change-Id: I416aee7cdfc4a8cf5da92879109f97e0bbfab265 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* Rename refreshThreshold property to refreshLeadTimeJuha Vuolle2024-12-192-25/+25
| | | | | | | | | | | | | | | Using the word "threshold" with a time span is somewhat ambiguous, and developers would need to read the documentation. The words "leadTime" should make the role of the property more obvious. Resulted from API review. Amends: 58c92af6e870fde2718a2aa9a6631a9c7ab40fad Pick-to: 6.9 Change-Id: Ia02745f4d9c5afaac7f46d979e24490f56d51469 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Magdalena Stojek <magdalena.stojek@qt.io>
* Change scope deprecation timeline from 6.11 to 6.13Juha Vuolle2024-12-191-3/+3
| | | | | | | | | | | | | | | | Scope deprecation is not urgent, and providing longer adaptation timeline is appropriate. Also this aligns with other Qt 6.9 deprecation timelines. Resulted from API review. Amends: bb03cf1627a64e5351214b04aee84d6d7d5cef07 Pick-to: 6.9 Change-Id: Iefdedb5e34b165ae9efc780a57cede1bdcab8b4e Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Magdalena Stojek <magdalena.stojek@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Rename isPolling property to pollingJuha Vuolle2024-12-191-1/+1
| | | | | | | | | | | | | | | | | | | To comply with API naming guideline. In this context the 'polling' can be considered an adjective/state, and the getter is prefixed with 'is', while the name of the property (and its change signal) is not prefixed. https://wiki.qt.io/API_Design_Principles See Naming Boolean Getters, Setters, and Properties Resulted from API review. Amends: 164e2d897fb7c3a60b518985774a4faa360ba2c9 Pick-to: 6.9 Change-Id: Iaf190edaf735ea32ca0ad66fe00a77a57bb037b4 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Get rid of QPair and mark the module as QPair freeIvan Solovev2024-12-197-37/+39
| | | | | | | | | | Amends 8e5e1012f9a9a9f01a12f631a3ed34570b6a4c5c which only cleaned up the public headers. Task-number: QTBUG-115841 Pick-to: 6.9 6.8 Change-Id: I16399e3ced49b91134e68c351f190720f88c3044 Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
* Ensure QAbstractOAuth2::scope is removed in Qt 7Ivan Solovev2024-12-191-3/+3
| | | | | | | | | | | | Use the new QT_REMOVAL_QT7_DEPRECATED_SINCE() macro to guarantee that the property will be automatically removed in Qt 7. Amends bb03cf1627a64e5351214b04aee84d6d7d5cef07 Task-number: QTBUG-132106 Pick-to: 6.9 Change-Id: I54bdb53a72dd51bc16311d50c82a41c48a31582e Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
* Qt 7: add QAbstractOAuth2::refreshTokens() virtual slotIvan Solovev2024-12-192-16/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | The base class already contains all properties and signals related to access token refreshing. However, we can not add a new virtual slot during Qt 6 lifetime. This patch pre-programs the addition of this slot to Qt 7 and adjusts the refresh token logic to call the new slot directly from the base class. This eliminates the need to manually implement auto-refresh logic in the derived classes. The name of the new slot is different from the pre-existing slots in the derived classes, so this patch also pre-programs the renaming of the relevant slots. The patch also pre-programs documentation changes by providing Qt 7 versions of the relevant docs. Picking this change to 6.9 to minimize the amount of merge conflict resolutions. Task-number: QTBUG-132106 Pick-to: 6.9 Change-Id: I453e9aae096abbfddcb8076f808d4a055850f7e0 Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
* Deprecate QOAuth2AuthorizationCodeFlow::accessTokenUrl propertyIvan Solovev2024-12-193-19/+34
| | | | | | | | | | | | | | | | | ... and schedule it for removal in Qt 7. Update most of the unit-test to use the new property, leaving just some of them with a conditional check, to make sure that the old API is still tested. [ChangeLog][QOAuth2AuthorizationCodeFlow] Deprecated accessTokenUrl property and scheduled it for removal in Qt 7. Use QAbstractOAuth2::tokenUrl instead. Task-number: QTBUG-132106 Pick-to: 6.9 Change-Id: I0bbb32854380268f8b7226859911b6fc3bd9289e Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
* Move tokenUrl property to QAbstractOAuth2Ivan Solovev2024-12-191-0/+66
| | | | | | | | | | | | | | | | | | | | | | | The property is common for both authorization code and device flows, so it makes sense to move it to the base class. And more broadly speaking, most OAuth2 flows use a token endpoint. One problem is that QOAuth2AuthorizationCodeFlow already has an accessTokenUrl property which is used for the same purpose. This patch implements this property in termes of the base tokenUrl property. The follow-up commit will deprecate the QOAuth2AuthorizationCodeFlow property and mark it for removal in Qt 7. There were no tests for the accessTokenUrl property and the related signal, so create a new test that checks both old and new properties. [ChangeLog][QAbstractOAuth2] Added tokenUrl property that holds the token endpoint URL. Task-number: QTBUG-132106 Pick-to: 6.9 Change-Id: I4e680e1013093041dcd3fa4f06e24b83cec83fc3 Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
* Change QOAuth2DeviceAuthorizationFlow::refreshAccessToken() return typeIvan Solovev2024-12-121-10/+20
| | | | | | | | | | | | | | | | | | | Initially the slot was returning bool, but the similar slot in QOAuth2AuthorizationCodeFlow has a void return type. This patch adjusts the return type of QOAuth2AuthorizationCodeFlow's version to void as well. That is done for consistency, and with a potential future refactoring in mind. The errors that can occur during the execution of the slot, are already reported by the requestFailed() signal, so adjust the tests to check this signal instead of the return value. Amends 164e2d897fb7c3a60b518985774a4faa360ba2c9. Pick-to: 6.9 Change-Id: I0529ee354fe884b93d0ad9bb0f5eaa810ca7fcd1 Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
* Finetune token expiration convenience functionalityJuha Vuolle2024-12-102-235/+123
| | | | | | | | | | | | | | | | | | - Detect case where refresh threshold is larger than token lifetime - Distinguish between client-side and server-side refresh timer updates in order to handle timeouts appropriately. An immediate refresh should only occur if initiated by client-side, in which case it happens only once (after that, the next update is initiated by server-side) - Minimum timeout value to avoid unthrottled refresh loop in case of a server misconfiguration - Simplify auto test cases by combining the two cases into a single data-driven case - Single out two corner-case autotests Pick-to: 6.9 Change-Id: Ia538e8b308564dc6f3e42103d72e724bbf226b69 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Add token expiration convenience to Device Flow classMagdalena Stojek2024-12-102-1/+188
| | | | | | | | | | | | | | | | Add automatic token refresh for expiring tokens in Device Flow class, if a refresh token is available. This functionality, previously implemented in Authorization Code Flow class, has now been extended to Device Flow following its merge. Add additional check for QOAuth2AuthorizationCodeFlow preventing unintened automatic refresh attempts. Pick-to: 6.9 Task-number: QTBUG-130844 Change-Id: I175abd0769d60d5440a3e84dc57d6f3d00193e41 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Change QAbstractOAuth2::expirationAt also when invalidatedJuha Vuolle2024-12-101-0/+82
| | | | | | | | | | | | | | Otherwise the expiresAt can remain as valid, leading the application to think that the token has a valid expiration time. [ChangeLog][QAbstractOAuth2] Change expirationAt also if expires_in wasn't provided, or has invalid value, and becomes invalid. Pick-to: 6.9 6.8 6.5 Fixes: QTBUG-131948 Change-Id: Ibded1d2322155814d2db98918f68a008cf2b96e6 Reviewed-by: Magdalena Stojek <magdalena.stojek@qt.io> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Add a method to manually define http callback hostnameJuha Vuolle2024-12-041-10/+29
| | | | | | | | | | | | | | | This allows setting an arbitrary hostname in case 'localhost' or IP literal are not preferable: http://localhost:1234/cb // pre-existing http://127.0.0.1:1234/cb // pre-existing http://my.localnet:1234/cb // new, possible with this commit [ChangeLog][QOAuthHttpServerReplyHandler] Added new API for manually specifying the callback/redirect_uri hostname Task-number: QTBUG-130159 Change-Id: I0d218fc43ea0dec35383c03b313c7f9d5f0f8593 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Improve callback/redirect_uri hostname settingJuha Vuolle2024-12-041-2/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Setting hostname part of redirect uri (callback) is important part to get correct, because authorization servers often expect a verbatim match between what has been registered, and what is sent as part of authorization request. This commit clarifies and improves specifying the hostname part. Historically the callback host was fixed to "127.0.0.1" which has its drawbacks (and can be outright wrong). The situation was later improved by using "localhost" hostname, which correctly maps to both IPv4 and IPv6 interfaces. However, there are authorization servers which require the use of IP literals, and reject "localhost". To address these issues, this commit consists of: - Map Any, AnyIPv4, and AnyIPv6 to "localhost". This mapping is logical because "localhost" will work then independent of what the actual used address is - Map IPv4 and IPv6 loopback addresses (LocalHost, LocalHostIPv6) to their IP literals 127.0.0.1 and ::1 These are well-known IP literal addresses, and mapping them to "localhost" does not bring an advantage - If user has provided a string literal, use that directly - Change default address to "LocalHost", which maps to hostname "127.0.0.1". This, in part, undoes the changed behavior where the default changed to "localhost". With this change, users that don't define callback address shouldn't notice a difference to the very original behavior All in all these changes should improve the compatibility with various authorization servers and provide more flexibility to users. Amends: fd49b7f6543e7b49be7847624c64ee86c4272ccd Amends: 4e03167088181bf513adcfb8aac93fb8efb3f420 [ChangeLog][QOAuthHttpServerReplyHandler] Changed and clarified callback hostname handling (especially localhost vs. 127.0.0.1) Pick-to: 6.8 Fixes: QTBUG-130159 Change-Id: I25dfb996d10f95fe60bdb4f46ea848edcb2528be Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Skip parts of OAuth1 autotestsJuha Vuolle2024-12-041-0/+5
| | | | | | | | | | | | The testing service originally hosted at http://term.ie/oauth seems no longer to exist. But since the host itself (term.ie) is reachable, tests are not skipped, but instead run and fail. Task-number: QTBUG-131869 Pick-to: 6.8 6.5 5.15 Change-Id: I3e2d20e45470f20ab78d5adff52b36945c95b0b2 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Magdalena Stojek <magdalena.stojek@qt.io>
* Add string literal suffix in an autotest caseJuha Vuolle2024-12-031-1/+1
| | | | | | | | | | Otherwise the string combinining is prune to problems with some platforms/compilers. Amends: 08f30372a7d3a08d566be5598ac4a37f564f0aeb Change-Id: I05aebf542adb52da9caff495d69d2d332b9c207e Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Fix and improve token request error reportingJuha Vuolle2024-11-292-0/+91
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | From QAbstractOAuth::Error documentation: NetworkError - Failed to connect to the server. ServerError - The server answered the request with an error, or its response was not successfully received The reply handler's usage of these error codes didn't match these criteria. Notably it used QNetworkReply::error() function, which mixes network, protocol, and HTTP status errors. As per OAuth RFC, it is common for the authorization server to respond with an HTTP error status like 400 Bad Request in case something is wrong either on the client-side or on the server-side. This commit makes a distinction between network/protocol errors, and errors where the server responded with an HTTP status (or errors which can be otherwise considered server-errors, like missing content-type header). Network/protocol errors are NetworkErrors, and other errors are ServerErrors. As a related change, one qCWarning is removed as redundant, because in practice tokenRequestErrorOccurred() handler also prints a warning. Also as a related change, empty JSON object branch was missing an error signal emission which is now added. Note: Picking this to branches earlier than 6.6 isn't particularly useful, because token request error reporting was introduced in 6.6. Prior to 6.6, an error results only in a qCWarning print, not an error signal emission. Amends: 32f29d3e227da206f262efa055d1cac895855a98 [ChangeLog][QOAuthHttpServerReplyHandler] Make a better distinction between NetworkErrors and ServerErrors with token requests. Pick-to: 6.8 Change-Id: I3ea8ca30da3e82867628ae5a90e2aa84e435d66d Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Add access token expiration convenience functionalityMagdalena Stojek2024-11-211-1/+194
| | | | | | | | | | | | | | | Add the convenience of automatically refreshing an expiring access token, if a refresh token is available. QAbstractOAuth2 class provides accessTokenAboutToExpire signal and autoRefresh and refreshThreshold properties for this. [ChangeLog][QAbstractOAuth2] Added new accessTokenAboutToExpire() signal, and autorefresh and refreshThreshold properties. Fixes: QTBUG-124332 Change-Id: I55f4333abfbed25de11688d5c20650d433a650de Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>