问题
The issue is with redirect URIs, I don't know what to set it to. Hase ANYONE been able to figure this out?
I get an error in Qt Creator's output pane that looks like this:
qt.networkauth.oauth2: Unexpected call
qt.networkauth.replyhandler: Error transferring https://oauth2.googleapis.com/token - server replied: Bad Request
Here's my code, a function called grant() that will return true open successful authentication. The helper class OAuth2Props returns all the data from the JSON file generated by Google.
bool grant() {
QOAuth2AuthorizationCodeFlow oauthFlow;
QObject::connect(&oauthFlow,
&QOAuth2AuthorizationCodeFlow::authorizeWithBrowser,
&QDesktopServices::openUrl);
oauthFlow.setScope("email");
oauthFlow.setAuthorizationUrl(OAuth2Props::authUri());
oauthFlow.setClientIdentifier(OAuth2Props::clientId());
oauthFlow.setAccessTokenUrl(OAuth2Props::tokenUri());
oauthFlow.setClientIdentifierSharedKey(OAuth2Props::clientSecret());
QOAuthHttpServerReplyHandler oauthReplyHandler(
QUrl(OAuth2Props::redirectUri()).port());
oauthFlow.setReplyHandler(&oauthReplyHandler);
QEventLoop eventLoop;
QObject::connect(&oauthFlow, &QOAuth2AuthorizationCodeFlow::granted,
&eventLoop, &QEventLoop::quit);
oauthFlow.grant();
eventLoop.exec();
return true;
}
Any thoughts on what I am doing wrong? The redirect URI I have set to http://127.0.0.1:65535/, I am guessing that's what I am doing wrong?
来源:https://stackoverflow.com/questions/62296641/unable-to-implement-google-sign-in-using-qoauth2authorizationcodeflow