<small id='ZAms3'></small><noframes id='ZAms3'>

    <bdo id='ZAms3'></bdo><ul id='ZAms3'></ul>

  1. <legend id='ZAms3'><style id='ZAms3'><dir id='ZAms3'><q id='ZAms3'></q></dir></style></legend>

    <tfoot id='ZAms3'></tfoot>
  2. <i id='ZAms3'><tr id='ZAms3'><dt id='ZAms3'><q id='ZAms3'><span id='ZAms3'><b id='ZAms3'><form id='ZAms3'><ins id='ZAms3'></ins><ul id='ZAms3'></ul><sub id='ZAms3'></sub></form><legend id='ZAms3'></legend><bdo id='ZAms3'><pre id='ZAms3'><center id='ZAms3'></center></pre></bdo></b><th id='ZAms3'></th></span></q></dt></tr></i><div id='ZAms3'><tfoot id='ZAms3'></tfoot><dl id='ZAms3'><fieldset id='ZAms3'></fieldset></dl></div>

      如何使用 QOAuth2AuthorizationCodeFlow 和 QOAuthHttpServerReplyHan

      How to set redirect_uri using QOAuth2AuthorizationCodeFlow and QOAuthHttpServerReplyHandler(如何使用 QOAuth2AuthorizationCodeFlow 和 QOAuthHttpServerReplyHandler 设置 redirect_uri)

        <tfoot id='qyumn'></tfoot>
          • <bdo id='qyumn'></bdo><ul id='qyumn'></ul>

              <i id='qyumn'><tr id='qyumn'><dt id='qyumn'><q id='qyumn'><span id='qyumn'><b id='qyumn'><form id='qyumn'><ins id='qyumn'></ins><ul id='qyumn'></ul><sub id='qyumn'></sub></form><legend id='qyumn'></legend><bdo id='qyumn'><pre id='qyumn'><center id='qyumn'></center></pre></bdo></b><th id='qyumn'></th></span></q></dt></tr></i><div id='qyumn'><tfoot id='qyumn'></tfoot><dl id='qyumn'><fieldset id='qyumn'></fieldset></dl></div>
                <tbody id='qyumn'></tbody>

              <legend id='qyumn'><style id='qyumn'><dir id='qyumn'><q id='qyumn'></q></dir></style></legend>

              <small id='qyumn'></small><noframes id='qyumn'>

              • 本文介绍了如何使用 QOAuth2AuthorizationCodeFlow 和 QOAuthHttpServerReplyHandler 设置 redirect_uri的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                对于使用 QT 的 networkauth 和新的 QOAuth2AuthorizationCodeFlow 对象的 OAuth 2.0,我该如何设置 redirect_uri?我的代码如下.这会导致发送以下身份验证 URL:

                For OAuth 2.0 using QT's networkauth and the new QOAuth2AuthorizationCodeFlow object, how can I set the redirect_uri? My code is below. It results in the following authenticate url being sent:

                QOAuth2AuthorizationCodeFlow::buildAuthenticateUrl:https://accounts.google.com/o/oauth2/auth?client_id=123-abc.apps.googleusercontent.com&redirect_uri=http://localhost:65535/cb&response_type=code&scope=email&state=iEIYn5sN

                QOAuth2AuthorizationCodeFlow::buildAuthenticateUrl: https://accounts.google.com/o/oauth2/auth?client_id=123-abc.apps.googleusercontent.com&redirect_uri=http://localhost:65535/cb&response_type=code&scope=email&state=iEIYn5sN

                将 redirect_uri 设置为http://localhost",导致来自谷歌的错误 400 redirect_uri_mismatch,这显然是期待要提供的实际重定向主机名.

                The setting of redirect_uri to "http://localhost", results in an Error 400 redirect_uri_mismatch from google which is obviously expecting the actual redirect hostname to be provided.

                GoogleGateway::GoogleGateway() {
                
                auto google = new QOAuth2AuthorizationCodeFlow;
                google->setScope("email");
                
                this->connect(google, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, &QDesktopServices::openUrl);
                
                QString val;
                QFile file;
                file.setFileName("/home/me/client_secret.json");
                file.open(QIODevice::ReadOnly | QIODevice::Text);
                val = file.readAll();
                file.close();
                
                QJsonDocument document = QJsonDocument::fromJson(val.toUtf8());
                QJsonObject object = document.object();
                const auto settingsObject = object["web"].toObject();
                const QUrl authUri(settingsObject["auth_uri"].toString());
                const auto clientId = settingsObject["client_id"].toString();
                const QUrl tokenUri(settingsObject["token_uri"].toString());
                const auto clientSecret(settingsObject["client_secret"].toString());
                const auto redirectUris = settingsObject["redirect_uris"].toArray();
                const QUrl redirectUri(redirectUris[0].toString());
                const auto port = static_cast<quint16>(redirectUri.port());
                
                google->setAuthorizationUrl(authUri);
                google->setClientIdentifier(clientId);
                google->setAccessTokenUrl(tokenUri);
                google->setClientIdentifierSharedKey(clientSecret);
                
                auto replyHandler = new QOAuthHttpServerReplyHandler(port, this);
                google->setReplyHandler(replyHandler);
                
                google->grant();
                }
                

                要设置redirect_uri,我试过替换:

                To set the redirect_uri, I've tried replacing:

                auto replyHandler = new QOAuthHttpServerReplyHandler(port, this);
                

                QHostAddress hostaddress = QHostAddress(quint32(1233...));
                auto replyHandler = new QOAuthHttpServerReplyHandler(hostaddress, port, this);
                

                结果没有变化.

                也试过插入:

                replyHandler->setProperty("redirect_uri", "http://abc.xyz.com:65535/cb");
                

                结果也没有变化.

                在 Qt/5.8/Src/qtnetworkauth/src/oauth/qoauthhttpserverreplyhandler.cpp 中,我们看到回调地址看起来很可疑:

                In Qt/5.8/Src/qtnetworkauth/src/oauth/qoauthhttpserverreplyhandler.cpp, we see that the callback address looks suspiciously hard-coded:

                QString QOAuthHttpServerReplyHandler::callback() const
                {
                    Q_D(const QOAuthHttpServerReplyHandler);
                
                    Q_ASSERT(d->httpServer.isListening());
                    const QUrl url(QString::fromLatin1("http://localhost:%1/cb").arg(d->httpServer.serverPort()));
                    return url.toString(QUrl::EncodeDelimiters);
                }
                

                这个callback()依次在Qt/5.8/Src/qtnetworkauth/src/oauth/qoauth2authorizationcodeflow.cpp中用来设置redirectUri值:

                This callback() is in turn used in Qt/5.8/Src/qtnetworkauth/src/oauth/qoauth2authorizationcodeflow.cpp to set the redirectUri value:

                QUrl QOAuth2AuthorizationCodeFlow::buildAuthenticateUrl(const QVariantMap &parameters)
                {
                    Q_D(QOAuth2AuthorizationCodeFlow);
                    using Key = QAbstractOAuth2Private::OAuth2KeyString;
                
                    if (d->state.isEmpty())
                        setState(QAbstractOAuth2Private::generateRandomState());
                    Q_ASSERT(!d->state.isEmpty());
                    const QString state = d->state;
                
                    QVariantMap p(parameters);
                    QUrl url(d->authorizationUrl);
                    p.insert(Key::responseType, responseType());
                    p.insert(Key::clientIdentifier, d->clientCredentials.first);
                    p.insert(Key::redirectUri, callback());
                    p.insert(Key::scope, d->scope);
                    p.insert(Key::state, state);
                    if (d->modifyParametersFunction)
                        d->modifyParametersFunction(Stage::RequestingAuthorization, &p);
                    url.setQuery(d->createQuery(p));
                    connect(d->replyHandler.data(), &QAbstractOAuthReplyHandler::callbackReceived, this,
                            &QOAuth2AuthorizationCodeFlow::authorizationCallbackReceived, Qt::UniqueConnection);
                    setStatus(QAbstractOAuth::Status::NotAuthenticated);
                    qDebug("QOAuth2AuthorizationCodeFlow::buildAuthenticateUrl: %s", qPrintable(url.toString()));
                    return url;
                }
                

                这是一个错误吗?

                推荐答案

                我刚刚通过子类化 MyOAuthHttpServerReplyHandler 并覆盖 callback() 的定义来返回 URI 解决了这个问题我想要.

                I just solved this by subclassing MyOAuthHttpServerReplyHandler and overriding the definition of callback() to return the URI I wanted.

                这篇关于如何使用 QOAuth2AuthorizationCodeFlow 和 QOAuthHttpServerReplyHandler 设置 redirect_uri的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                Delay Loading DLLs(延迟加载 DLL)
                Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                Loading a dll from a dll?(从 dll 加载 dll?)
                  <tbody id='mcty2'></tbody>

                <i id='mcty2'><tr id='mcty2'><dt id='mcty2'><q id='mcty2'><span id='mcty2'><b id='mcty2'><form id='mcty2'><ins id='mcty2'></ins><ul id='mcty2'></ul><sub id='mcty2'></sub></form><legend id='mcty2'></legend><bdo id='mcty2'><pre id='mcty2'><center id='mcty2'></center></pre></bdo></b><th id='mcty2'></th></span></q></dt></tr></i><div id='mcty2'><tfoot id='mcty2'></tfoot><dl id='mcty2'><fieldset id='mcty2'></fieldset></dl></div>
                  <bdo id='mcty2'></bdo><ul id='mcty2'></ul>

                    1. <tfoot id='mcty2'></tfoot>
                      • <legend id='mcty2'><style id='mcty2'><dir id='mcty2'><q id='mcty2'></q></dir></style></legend>

                        <small id='mcty2'></small><noframes id='mcty2'>