diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2024-05-08 13:13:04 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2024-05-13 11:14:54 -0700 |
commit | 7d0995068ae67bad291b4e3066085700e7481758 (patch) | |
tree | 9e6885ba4a223e05b12befc04aee1d9bf6661519 /src/oauth/qoauthhttpserverreplyhandler.cpp | |
parent | fd49b7f6543e7b49be7847624c64ee86c4272ccd (diff) |
QOAuthHttpServerReplyHandler: don't assume the server is localhost
The constructors allow passing a different address than 127.0.0.1, so
get the address we did bind to from the QTcpServer and use that in
constructing the URL.
Additionally, use QUrl to construct the URL, instead of doing string
concatenation. This ensures we do get a proper URL.
Pick-to: 6.7
Change-Id: Ie30a3caf09ef4176bb36fffd17cd9c921a2fc8c6
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/oauth/qoauthhttpserverreplyhandler.cpp')
-rw-r--r-- | src/oauth/qoauthhttpserverreplyhandler.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/oauth/qoauthhttpserverreplyhandler.cpp b/src/oauth/qoauthhttpserverreplyhandler.cpp index 9d93c62..2612936 100644 --- a/src/oauth/qoauthhttpserverreplyhandler.cpp +++ b/src/oauth/qoauthhttpserverreplyhandler.cpp @@ -254,10 +254,17 @@ QString QOAuthHttpServerReplyHandler::callback() const Q_ASSERT(d->httpServer.isListening()); QUrl url; url.setScheme(u"http"_s); - url.setHost(u"127.0.0.1"_s); url.setPort(d->httpServer.serverPort()); url.setPath(d->path); + // convert Any and Localhost addresses to "localhost" + QHostAddress host = d->httpServer.serverAddress(); + if (host.isLoopback() || host == QHostAddress::AnyIPv4 || host == QHostAddress::Any + || host == QHostAddress::AnyIPv6) + url.setHost(u"localhost"_s); + else + url.setHost(host.toString()); + return url.toString(QUrl::EncodeDelimiters); } |