android – Google Sign-in Using Firebase and Qt-ThrowExceptions

Exception or error:

I’m trying to implement Google Sign-in option for my android app using Qt and Firebase Google Authentication by using Connecting your Qt application with Google Services using OAuth 2.0 and Authenticate Using Google Sign-In and C++.

After clicking on a push button in my app the consent page (if I didn’t misname it) loads correctly which allows the user to choose his/her desired google account but after that nothing happens. I don’t know whether the problem is with my redirected URI or something else.
I have enabled Google Sign-in Option in my Firebase Console and followed the suggested steps in this Question. What am I missing or doing wrong here?

Here is my code:

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();
        }
    }
    );
            });
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *