Beispiel #1
0
void TwitterEditAccountWidget::authorizeUser()
{
    kDebug();
    qoauth = new QOAuth::Interface(new KIO::AccessManager(this), this);//TODO KDE 4.5 Change to use new class.
    // set the consumer key and secret
    qoauth->setConsumerKey( twitterConsumerKey );
    qoauth->setConsumerSecret( twitterConsumerSecret );
    // set a timeout for requests (in msecs)
    qoauth->setRequestTimeout( 20000 );
    qoauth->setIgnoreSslErrors(true);

    QOAuth::ParamMap otherArgs;

    // send a request for an unauthorized token
    QOAuth::ParamMap reply =
        qoauth->requestToken( "https://twitter.com/oauth/request_token",
                              QOAuth::GET, QOAuth::HMAC_SHA1 );

    // if no error occurred, read the received token and token secret
    if ( qoauth->error() == QOAuth::NoError ) {
        token = reply.value( QOAuth::tokenParameterName() );
        tokenSecret = reply.value( QOAuth::tokenSecretParameterName() );
        kDebug()<<"token: "<<token;
        QUrl url("https://twitter.com/oauth/authorize");
        url.addQueryItem("oauth_token", token);
        url.addQueryItem( "oauth_callback", "oob" );
        Choqok::openUrl(url);
        getPinCode();
    } else {
        kDebug()<<"ERROR: " <<qoauth->error()<<' '<<Choqok::qoauthErrorText(qoauth->error());
        KMessageBox::detailedError(this, i18n("Authorization Error"),
                                   Choqok::qoauthErrorText(qoauth->error()));
    }
}
Beispiel #2
0
void TwitterEditAccountWidget::getPinCode()
{
    isAuthenticated = false;
    while(!isAuthenticated){
        QString verifier = KInputDialog::getText( i18n("PIN number"),
                                                  i18n("Enter PIN number received from Twitter:"));
        if(verifier.isEmpty())
            return;
        QOAuth::ParamMap otherArgs;
        otherArgs.insert( "oauth_verifier", verifier.toUtf8() );

        // send a request to exchange Request Token for an Access Token
        QOAuth::ParamMap reply =
            qoauth->accessToken( "https://twitter.com/oauth/access_token", QOAuth::POST, token,
                                tokenSecret, QOAuth::HMAC_SHA1, otherArgs );
        // if no error occurred, read the Access Token (and other arguments, if applicable)
        if ( qoauth->error() == QOAuth::NoError ) {
            username = reply.value( "screen_name" );
            token = reply.value( QOAuth::tokenParameterName() );
            tokenSecret = reply.value( QOAuth::tokenSecretParameterName() );
            setAuthenticated(true);
            KMessageBox::information(this, i18n("Choqok is authorized successfully."),
                                     i18n("Authorized"));
        } else {
            kDebug()<<"ERROR: "<<qoauth->error()<<' '<<Choqok::qoauthErrorText(qoauth->error());
            KMessageBox::detailedError(this, i18n("Authorization Error"),
                                    Choqok::qoauthErrorText(qoauth->error()));
        }
    }
}
Beispiel #3
0
bool PlurkApiOAuth::getPinCode()
{
    QString verifier = KInputDialog::getText( "Security code",
                                              "Security code recieved from Plurk",
                                                    "Enter security code:");
    if(verifier.isEmpty())
        return false;
    QOAuth::ParamMap otherArgs;
    otherArgs.insert( "oauth_verifier", verifier.toUtf8() );

    // send a request to exchange Request Token for an Access Token
    QOAuth::ParamMap reply =
    d->qoauth->accessToken( QString(plurkOAuthAccessToken),
                         QOAuth::GET, d->oauthToken, d->oauthTokenSecret, QOAuth::HMAC_SHA1, otherArgs );
    // if no error occurred, read the Access Token (and other arguments, if applicable)
    if ( d->qoauth->error() == QOAuth::NoError ) {
        d->username = reply.value( "screen_name" );
        d->oauthToken = reply.value( QOAuth::tokenParameterName() );
        d->oauthTokenSecret = reply.value( QOAuth::tokenSecretParameterName() );
        // TODO use a parent widget for this message box
        KMessageBox::information(0, "Plurk is authorized successfully.",
                                 "Authorized");
        return true;
    } else {
        kDebug() << "ERROR: " << d->qoauth->error() << ' ' << oauthErrorText(d->qoauth->error());
        KMessageBox::detailedError(0, "Authorization Error",
                                oauthErrorText(d->qoauth->error()));
    }

    return false;
}
Beispiel #4
0
bool PlurkApiOAuth::authorizeUser()
{
    kDebug();
    // set the consumer key and secret
    d->qoauth->setConsumerKey( plurkConsumerKey );
    d->qoauth->setConsumerSecret( plurkConsumerSecret );
    // set a timeout for requests (in msecs)
    d->qoauth->setRequestTimeout( 20000 );
    d->qoauth->setIgnoreSslErrors(true);

    QOAuth::ParamMap otherArgs;

    // send a request for an unauthorized token
    QOAuth::ParamMap reply =
        d->qoauth->requestToken( plurkOAuthRequestTokenURL, QOAuth::GET, QOAuth::HMAC_SHA1 );

    // if no error occurred, read the received token and token secret
    if ( d->qoauth->error() == QOAuth::NoError ) {
        d->oauthToken = reply.value( QOAuth::tokenParameterName() );
        d->oauthTokenSecret = reply.value( QOAuth::tokenSecretParameterName() );
        kDebug() << "token: " << d->oauthToken;
        QUrl url(plurkOAuthAuthorizeURL);
        url.addQueryItem("oauth_token", d->oauthToken);
        url.addQueryItem( "oauth_callback", "oob" );
        KToolInvocation::invokeBrowser(url.toString());
        return getPinCode();
    } else {
        kDebug() << "ERROR: " << d->qoauth->error() << ' ' << oauthErrorText(d->qoauth->error());
        // TODO use a parent widget for this message box
        KMessageBox::detailedError(0, "Authorization Error",
                                   oauthErrorText(d->qoauth->error()));
    }

    return false;
}
Beispiel #5
0
void OAuthWizard::authorize()
{
  ui_p->pinEdit->setEnabled( false );
  QOAuth::ParamMap otherArgs;
  otherArgs.insert( ParamVerifier, ui_p->pinEdit->text().toAscii() );
  QOAuth::ParamMap accessToken = qoauth->accessToken( TwitterAccessTokenURL, QOAuth::POST, token,
                                                      tokenSecret, QOAuth::HMAC_SHA1, otherArgs );

  if ( qoauth->error() != QOAuth::NoError ) {
    ui_p->pinEdit->hide();
    ui_p->pinLabel->setText( tr( "Either the PIN you entered is incorrect, or a network-related problem occured. Please try again later." ) );
    ui_p->okButton->setText( tr( "Retry" ) );
    adjustSize();
    resize( width(), height() * 1.5 );
    disconnect( ui_p->okButton, SIGNAL(clicked()), this, SLOT(authorize()) );
    connect( ui_p->okButton, SIGNAL(clicked()), this, SLOT(openUrl()) );
    state = false;
    return;
  }

  screenName = accessToken.value( ParamScreenName );
  token = accessToken.value( QOAuth::ParamToken );
  tokenSecret = accessToken.value( QOAuth::ParamTokenSecret );
  state = true;
  accept();
}
Beispiel #6
0
void OAuthWizard::openUrl()
{
  QOAuth::ParamMap requestToken = qoauth->requestToken( TwitterRequestTokenURL, QOAuth::GET, QOAuth::HMAC_SHA1 );

  if ( qoauth->error() != QOAuth::NoError ) {
    if ( sender() == ui_p->okButton ) {
      delete ui_o->widget->layout();

      ui_p->okButton->deleteLater();
      ui_p->pinEdit->deleteLater();
      ui_p->pinLabel->deleteLater();
      ui_a->setupUi(ui_o->widget);
    }

    ui_a->allowLabel->setText( tr( "There was a network-related problem with completing the request. Please try again later." ) );
    ui_a->allowButton->setText( tr( "Retry" ) );
    adjustSize();
    resize( width(), height() * 1.5 );
    state = false;
    return;
  }

  token = requestToken.value( QOAuth::ParamToken );
  tokenSecret = requestToken.value( QOAuth::ParamTokenSecret );

  QString url = TwitterAuthorizeURL;

  url.append( "?" );
  url.append( "&" + QOAuth::ParamToken + "=" + token );
  url.append( "&" + ParamCallback + "=" + ParamCallbackValue );

  QDesktopServices::openUrl( QUrl( url ) );

  delete ui_o->widget->layout();

  if ( sender() == ui_p->okButton ) {
    delete ui_o->widget->layout();

    ui_p->okButton->deleteLater();
    ui_p->pinEdit->deleteLater();
    ui_p->pinLabel->deleteLater();
  } else {
    ui_a->allowLabel->deleteLater();
    ui_a->allowButton->deleteLater();
  }

  ui_p->setupUi(ui_o->widget);
  ui_p->pinEdit->setValidator( new QRegExpValidator( QRegExp( "\\d{6}" ), this ) );
  connect( ui_p->okButton, SIGNAL(clicked()), this, SLOT(authorize()) );
  connect( ui_p->pinEdit, SIGNAL(textChanged(QString)), this, SLOT(setOkButtonEnabled()) );
}
Beispiel #7
0
void RequestTokenJob::start()
{
    QOAuth::Interface oauth(this);
    oauth.setConsumerKey(CONSUMER_KEY);
    oauth.setConsumerSecret(CONSUMER_SECRET);

    QOAuth::ParamMap map = oauth.requestToken(REQUEST_TOKEN_URL, QOAuth::POST, QOAuth::HMAC_SHA1);

    QByteArray oauthToken, oauthTokenSecret;
    bool success = false;
    if (oauth.error() == 200) {
        oauthToken = map.value (QOAuth::tokenParameterName());
        oauthTokenSecret = map.value (QOAuth::tokenSecretParameterName());
        success = true;
    }

    emit finished(success, oauthToken, oauthTokenSecret);
}