Unable to implement Google Sign-In using QOAuth2AuthorizationCodeFlow

给你一囗甜甜゛ 提交于 2020-06-13 08:20:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!