Я пытаюсь реализовать опцию Google Sign-in
для моего приложения android, используя Qt
и Firebase Google Authentication
, используя Подключение приложения Qt к сервисам Google с использованием OAuth 2.0 и Authenticate Использование входа в Google и C ++ .
После нажатия на кнопку pu sh в моем приложении страница согласия (, если я ее не назвал ) загружается правильно, которая позволяет пользователю выбрать желаемую учетную запись Google, но после этого ничего не происходит. Я не знаю, проблема с моим redirected URI
или с чем-то еще. Я включил Google Sign-in Option
в своем Firebase Console
и выполнил предложенные шаги в этом Вопросе . Что я здесь упускаю или делаю не так?
Вот мой код:
this->google = new QOAuth2AuthorizationCodeFlow(this);
this->google->setScope("email");
connect(this->google, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, &QDesktopServices::openUrl);
QByteArray val;
QFile file;
file.setFileName(QDir::toNativeSeparators(":/client_secret.json"));
if(file.open(QIODevice::ReadOnly | QIODevice::Text))
{
val = file.readAll();
file.close();
}
QJsonDocument document = QJsonDocument::fromJson(val);
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("https://MYAPP.firebaseapp.com/__/auth/handler");
const auto port = static_cast<quint16>(redirectUri.port());
this->google->setAuthorizationUrl(authUri);
this->google->setClientIdentifier(clientId);
this->google->setAccessTokenUrl(tokenUri);
this->google->setClientIdentifierSharedKey(clientSecret);
auto replyHandler = new QOAuthHttpServerReplyHandler(port, this);
replyHandler->setProperty("redirect_uri", "https://MYAPP.firebaseapp.com/__/auth/handler");
this->google->setReplyHandler(replyHandler);
this->google->grant();
connect(this->google, &QOAuth2AuthorizationCodeFlow::granted, [=](){
firebase::auth::Auth* auth = firebase::auth::Auth::GetAuth(_app);
firebase::auth::Credential credential = firebase::auth::GoogleAuthProvider::GetCredential(google->token().toUtf8(),nullptr);
firebase::Future<firebase::auth::User*> result = auth->SignInWithCredential(credential);
result.OnCompletion([&](const firebase::Future<firebase::auth::User*>& result)
{
if (result.error()==0)
{
qDebug() << "good to go";
}
else
{
qDebug() << result.error_message();
}
}
);
});