D
D
de-dup-i-dipi2021-02-23 16:35:20
OAuth
de-dup-i-dipi, 2021-02-23 16:35:20

Qt and oauth authorization?

I am writing a small application in c++, oauth2 authorization through a browser. For standalone it is recommended to use redirect_uri as oob. Upon confirmation, the user opens a window with a code. How can it be done so that the user does not have to copy the code and paste it into the application, but the application receives a token at the address and moves on? I did not find examples using oob, everything is tied only to the use of localhost'a.

auto replyHandler = new QOAuthHttpServerReplyHandler(this);
oauth2.setReplyHandler(replyHandler);
oauth2.setAuthorizationUrl(QUrl("https://site.ru/oauth/authorize"));
oauth2.setAccessTokenUrl(QUrl("https://site.ru/oauth/token"));
oauth2.setClientIdentifier(QString("client_id"));
oauth2.setClientIdentifierSharedKey(QString("client_secret"));

oauth2.setModifyParametersFunction([](QAbstractOAuth::Stage stage, QVariantMap *parameters) {
    (*parameters)["redirect_uri"] = QUrl("urn:ietf:wg:oauth:2.0:oob");
});

connect(&oauth2, &QOAuth2AuthorizationCodeFlow::statusChanged, [=](QAbstractOAuth::Status status) {
    if (status == QAbstractOAuth::Status::Granted)
    {
        qDebug() << "Granted";    
    }
    else
    {
        qDebug() << "Not granted";
    }
});

connect(&oauth2, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, &QDesktopServices::openUrl);
oauth2.grant();

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question