QA의 networkauth와 새로운 QOAuth2AuthorizationCodeFlow 객체를 사용하는 OAuth 2.0의 경우 redirect_uri를 어떻게 설정합니까? 내 코드는 아래와 같습니다. 그것은 다음과 같은 인증 할 URL 결과가 전송되는 :QOAuth2AuthorizationCodeFlow 및 QOAuthHttpServerReplyHandler를 사용하여 redirect_uri를 설정하는 방법
QOAuth2AuthorizationCodeFlow :: buildAuthenticateUrl : redirect_uri로의 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
설정을 "http://localhost"분명히에 실제 리디렉션 호스트 이름을 기대하고있다 구글에서 오류 400 redirect_uri_mismatch 결과 제공된.
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로를 설정하려면, 나는 교체 시도했다 :
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");
을도 결과에 변화없이.
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);
}
이 콜백은() Qt는에 사용 차례입니다 :
Qt는에서/5.8/src에/qtnetworkauth/SRC/OAuth를/qoauthhttpserverreplyhandler.cpp, 우리는 콜백 주소가 의심 하드 코딩 보이는 것을 볼 수
QUrl QOAuth2AuthorizationCodeFlow::buildAuthenticateUrl(const QVariantMap ¶meters)
{
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;
}
이 버그가 : /5.8/Src/qtnetworkauth/src/oauth/qoauth2authorizationcodeflow.cpp는 redirectUri 값을 설정하는 방법?
비슷하게 혼란스러운 사람은 https://bugreports.qt.io/browse/QTBUG-59653입니다. – myk