Exemplo n.º 1
0
void OAuth2::startLogin(bool bForce)
{
    if(m_strClientID == "YOUR_CLIENT_ID_HERE" || m_strRedirectURI == "YOUR_REDIRECT_URI_HERE" ||
        m_strClientSecret == "YOUR_CLIENT_SECRET_HERE")
    {
        QMessageBox::warning(m_pParent, "Warning",
                             "To work with application you need to register your own application in <b>Google</b>.\n"
                             "Learn more from <a href='http://code.google.com/p/qt-google-latitude/wiki/HowToRegisterYourApplicationInGoogle'>here</a>");
        return;
    }

    if(m_strRefreshToken.isEmpty() || bForce)
    {
        if (m_pLoginDialog != NULL) {
            delete m_pLoginDialog;
        }
        m_pLoginDialog = new LoginDialog(m_pParent);
        connect(m_pLoginDialog, SIGNAL(accessTokenObtained()), this, SLOT(accessTokenObtained()));
        connect(m_pLoginDialog, SIGNAL(codeObtained()), this, SLOT(codeObtained()));

        m_pLoginDialog->setLoginUrl(permanentLoginUrl());
        m_pLoginDialog->show();
    }
    else
    {
        getAccessTokenFromRefreshToken();
    }
}
Exemplo n.º 2
0
OAuth2::OAuth2(QWidget* parent)
{
    m_strEndPoint = "https://accounts.google.com/o/oauth2/auth";
    m_strScope = "https://www.googleapis.com/auth/books";
    m_strClientID = "YOUR_CLIENT_ID_HERE";
    m_strRedirectURI = "YOUR_REDIRECT_URI_HERE";
    m_strResponseType = "token";

    m_strCompanyName = "Google"; //You company here
    m_strAppName = "Test Google API Client"; //Your application name here

    m_pLoginDialog = new LoginDialog(parent);
    m_pParent = parent;
    connect(m_pLoginDialog, SIGNAL(accessTokenObtained()), this, SLOT(accessTokenObtained()));
}
Exemplo n.º 3
0
OAuth2::OAuth2(QWidget* parent)
{
    //You need to login to Google, so first you need to create simple
    //Google account. Then you can visit the page
    //
    // https://code.google.com/apis/console
    //
    //there you can create your application. You need to check access to Calendar API.
    //
    //Then  you can see credentials of your application.
    //You need to copy and paste Client_ID and Redirect_URI to the strings below.
    //
    m_strEndPoint = "https://accounts.google.com/o/oauth2/auth";
    m_strScope = "https://www.googleapis.com/auth/calendar"; //Access to Calendar service
    m_strClientID = "YOUR_CLIENT_ID_HERE";
    m_strRedirectURI = "YOUR_REDIRECT_URI_HERE";
    m_strResponseType = "token";

    m_pLoginDialog = new LoginDialog(parent);
    m_pParent = parent;
    connect(m_pLoginDialog, SIGNAL(accessTokenObtained()), this, SLOT(accessTokenObtained()));
}
Exemplo n.º 4
0
void LoginDialog::loadFinished(bool b)
{
    QApplication::restoreOverrideCursor();
    qDebug() << "loadFinished with" << b;
    QString title = ui->webView->title();

    // Check if we got the token
    if (title.startsWith ("Success code=")) {
        m_strAccessToken = title.section("=", 1, 1);
        qDebug() << "Access token = " << m_strAccessToken;
        emit accessTokenObtained();
        QDialog::accept();
    }
}
Exemplo n.º 5
0
void LoginDialog::urlChanged(const QUrl &url)
{
    qDebug() << "URL =" << url;
    QString str = url.toString();
    if(str.indexOf("access_token") != -1)
    {
        QStringList query = str.split("#");
        QStringList lst = query[1].split("&");
        for (int i=0; i<lst.count(); i++ )
        {
            QStringList pair = lst[i].split("=");
            if (pair[0] == "access_token")
            {
                m_strAccessToken = pair[1];
                emit accessTokenObtained();
                QDialog::accept();
            }
        }
    }
}
Exemplo n.º 6
0
#include <qjson/parser.h>
#include "settings.h"

OAuth2::OAuth2(QWidget* parent)
{
    connect (&m_networkAccessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(analyzeReply(QNetworkReply*)));

    m_strEndPoint = "https://accounts.google.com/o/oauth2/auth";
    m_strScope = "https://www.googleapis.com/auth/calendar"; //Access to Calendar service
    m_strClientID = "269204810048.apps.googleusercontent.com";
    m_strRedirectURI = "urn:ietf:wg:oauth:2.0:oob";
    m_strResponseType = "code";

    m_pLoginDialog = new LoginDialog(parent);
    m_pParent = parent;
    connect(m_pLoginDialog, SIGNAL(accessTokenObtained()), this, SLOT(authorizationTokenObtained()));
}

void
OAuth2::analyzeReply(QNetworkReply *reply)
{
    QByteArray response = reply->readAll();
    QJson::Parser parser;
    bool ok;

    qDebug() << "Reply received, starting to parse";
    qDebug() << "Response: " << QString(response);

    QVariantMap result = parser.parse(response, &ok).toMap();

    if (!ok)