Beispiel #1
0
void O1::unlink() {
    trace() << "O1::unlink";
    if (linked()) {
        setToken("");
        setTokenSecret("");
        emit linkedChanged();
    }
    emit linkingSucceeded();
}
Beispiel #2
0
Datei: o2gft.cpp Projekt: Sky/o2
void O2Gft::onTokenReplyFinished()
{
    qDebug() << "O2Gft::onTokenReplyFinished";

    QNetworkReply *tokenReply = qobject_cast<QNetworkReply *>(sender());
    if (tokenReply->error() == QNetworkReply::NoError) {
        QByteArray replyData = tokenReply->readAll();
        QScriptEngine engine;
        QScriptValueIterator it(engine.evaluate("(" + QString(replyData) + ")"));
        QVariantMap tokens;

        while (it.hasNext()) {
            it.next();
            tokens.insert(it.name(), it.value().toVariant());
        }

        // Check for mandatory tokens
        if (tokens.contains(O2_OAUTH2_ACCESS_TOKEN)) {
            setToken(tokens.take(O2_OAUTH2_ACCESS_TOKEN).toString());

            //
            setIdToken(tokens.take(O2_OAUTH2_ID_TOKEN).toString());

            //
            bool ok = false;
            int expiresIn = tokens.take(O2_OAUTH2_EXPIRES_IN).toInt(&ok);
            if (ok) {
                qDebug() << "Token expires in" << expiresIn << "seconds";
                setExpires(QDateTime::currentMSecsSinceEpoch() / 1000 + expiresIn);
            }
            setRefreshToken(tokens.take(O2_OAUTH2_REFRESH_TOKEN).toString());
            // Set extra tokens if any
            if (!tokens.isEmpty()) {
                setExtraTokens(tokens);
            }
            timedReplies_.remove(tokenReply);
            emit linkedChanged();
            emit tokenChanged();
            emit linkingSucceeded();
        } else {
            qWarning() << "O2::onTokenReplyFinished: oauth_token missing from response" << replyData;
            emit linkedChanged();
            emit tokenChanged();
            emit linkingFailed();
        }
    }
    tokenReply->deleteLater();
}
Beispiel #3
0
YoutubeController::YoutubeController(QObject *parent): QObject(parent),
    commentsTimerId_(0),
    updateMessagesIntervalMs_(DEFAULT_YOUTUBE_UPDATE_MESSAGES_INTERVAL_MS),
    liveChatId_("")
{
    o2youtube_ = new O2Youtube(this);

    o2youtube_->setClientId("463300085238-11h8th4cbl9uoi4rd8pcl0e19sspn1s8.apps.googleusercontent.com");
    o2youtube_->setClientSecret("PZE0m3Ym4lZRKWDWk6KQ9c7T");

    
    connect(o2youtube_, SIGNAL(linkedChanged()), this, SLOT(onLinkedChanged()));
    connect(o2youtube_, SIGNAL(linkingFailed()), this, SLOT(onLinkingFailed()));
    connect(o2youtube_, SIGNAL(linkingSucceeded()), this, SLOT(onLinkingSucceeded()));
    connect(o2youtube_, SIGNAL(openBrowser(QUrl)), this, SLOT(onOpenBrowser(QUrl)));
    connect(o2youtube_, SIGNAL(closeBrowser()), this, SLOT(onCloseBrowser()));

    api_ = new YoutubeApi(this);
    connect(api_, SIGNAL(broadcastModelChanged()),this, SLOT(broadcastModelChanged()));
    connect(api_, SIGNAL(commentModelChanged()),this, SLOT(commentModelChanged()));
}
Beispiel #4
0
void Oauth2::link()
{
    trace() << "O2::link";

    if (linked()) {
        trace() << " Linked already";
        emit linkingSucceeded();
        return;
    }

    if(grantFlow_ == GrantFlowAuthorizationCode){

        // Start listening to authentication replies
        replyServer_->listen(QHostAddress::Any, localPort_);

        // Save redirect URI, as we have to reuse it when requesting the access token
        redirectUri_ = localhostPolicy_.arg(replyServer_->serverPort());

        // Assemble intial authentication URL
        QList<QPair<QString, QString> > parameters;
        parameters.append(qMakePair(QString(O2_OAUTH2_RESPONSE_TYPE), (grantFlow_ == GrantFlowAuthorizationCode) ? QString(O2_OAUTH2_CODE) : QString(O2_OAUTH2_TOKEN)));
        parameters.append(qMakePair(QString(O2_OAUTH2_CLIENT_ID), clientId_));
        parameters.append(qMakePair(QString(O2_OAUTH2_REDIRECT_URI), redirectUri_));
        // parameters.append(qMakePair(QString(OAUTH2_REDIRECT_URI), QString(QUrl::toPercentEncoding(redirectUri_))));
        parameters.append(qMakePair(QString(O2_OAUTH2_SCOPE), scope_));
        parameters.append(qMakePair(QString(O2_OAUTH2_API_KEY), apiKey_));

        // Show authentication URL with a web browser
        QUrl url(requestUrl_);
    #if QT_VERSION < 0x050000
        url.setQueryItems(parameters);
    #else
        QUrlQuery query(url);
        query.setQueryItems(parameters);
        url.setQuery(query);
    #endif

        trace() << "Emit openBrowser" << url.toString();
        emit openBrowser(url);

    }

    else if(grantFlow_ == GrantFlowResourceOwnerPasswordCredentials)
    {
        QUrl url(tokenUrl_);

        QUrlQuery params;
        params.addQueryItem(O2_OAUTH2_CLIENT_ID,clientId_);
        params.addQueryItem(O2_OAUTH2_CLIENT_SECRET,clientSecret_);
        params.addQueryItem(O2_OAUTH2_USERNAME,username_);
        params.addQueryItem(O2_OAUTH2_PASSWORD,password_);
        params.addQueryItem(O2_OAUTH2_GRANT_TYPE,"password");
        params.addQueryItem("device_uid", getMacAddress());
        params.addQueryItem("device_name", "PC (" + QHostInfo::localHostName() + ")");

        QNetworkRequest tokenRequest(url);
        tokenRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
        QNetworkReply *tokenReply = manager_->post(tokenRequest, params.toString(QUrl::FullyEncoded).toUtf8());

        connect(tokenReply, SIGNAL(finished()), this, SLOT(onTokenReplyFinished()), Qt::QueuedConnection);
        connect(tokenReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onTokenReplyError(QNetworkReply::NetworkError)), Qt::QueuedConnection);
    }
}
Beispiel #5
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    //set up ui
    ui->setupUi(this);

    listModel= new QStandardItemModel(ui->listView);
    ui->listView->setModel(listModel);

    treeModel = new QStandardItemModel(ui->treeView);
    ui->treeView->setModel(treeModel);

    listMenu = new QMenu(this);
    treeMenu = new QMenu("TreeMenu",this);

    setting = new QSettings("my","feeder",this);
    subDialog = new SubscribeDialog(this);

    markArticleAsRead = new QAction("Mark As Read",this);
    markArticleAsUnread = new QAction("Mark As Unread",this);
    markFeedAllAsRead = new QAction("Mark All As Read",this);
    markCategoryAllAsRead = new QAction("Mark All As Read",this);
    //set up oauth2
    o2 = new O2(this);
    nam = new QNetworkAccessManager(this);
    o2req = new O2Requestor(nam,o2,this);
    o2->setClientId(CLIENT_ID);
    o2->setClientSecret(CLIENT_SECRET);
    o2->setRequestUrl(REQUEST_URL);
    o2->setTokenUrl(TOKEN_URL);
    o2->setScope(SCOPE);
    o2->setLocalPort(8080);
    o2->setRefreshTokenUrl(REFRESH_TOKEN_URL);

    store = new O2SettingsStore(setting,"myfeederkey",this);
    store->setGroupKey("OAuth");
    o2->setStore(store);

    //If we've already logged in, we can get userId and plan from
    //the local setting storage
    userId = store->value("id");
    plan = store->value("plan");
    qDebug() << userId<< plan;

    //We do the linking to log in. If we've already logged in,
    //it won't hurt any way.
    o2->link();

    //connect
    connect(o2, SIGNAL(linkedChanged()), this, SLOT(onLinkedChanged()));
    connect(o2, SIGNAL(linkingFailed()), this, SLOT(onLinkingFailed()));
    connect(o2, SIGNAL(linkingSucceeded()), this, SLOT(onLinkingSucceeded()));
    connect(o2, SIGNAL(openBrowser(QUrl)), this, SLOT(onOpenBrowser(QUrl)));
    connect(o2,SIGNAL(tokenChanged()),this,SLOT(onTokenChanged()));
    connect(ui->treeView,SIGNAL(clicked(QModelIndex)),this,SLOT(on_treeView_clicked(QModelIndex)));
    connect(o2req,SIGNAL(finished(int,QNetworkReply::NetworkError,QByteArray)),this,SLOT(onReqFinished(int,QNetworkReply::NetworkError,QByteArray)));
    connect(ui->listView,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(on_listView_customContextMenuRequested(QPoint)));
    connect(subDialog,SIGNAL(accepted()),this,SLOT(on_subscibe()));
    connect(listMenu,SIGNAL(triggered(QAction*)),this,SLOT(on_listView_menu_triggered(QAction*)));
    connect(treeMenu,SIGNAL(triggered(QAction*)),this,SLOT(on_treeView_menu_triggered(QAction*)));
    reqCategories();
}