mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-14 10:05:32 +02:00
Revamp twitter auth mechanism, which will hopefully remove false-positive auth success and allow de-authing
This commit is contained in:
@@ -61,10 +61,22 @@ TwitterPlugin::TwitterPlugin()
|
||||
m_connectTimer.start();
|
||||
}
|
||||
|
||||
void
|
||||
TwitterPlugin::configDialogAuthedSignalSlot( bool authed )
|
||||
{
|
||||
m_isAuthed = authed;
|
||||
if ( !authed )
|
||||
{
|
||||
TomahawkSettings::instance()->setTwitterScreenName( QString() );
|
||||
TomahawkSettings::instance()->setTwitterOAuthToken( QString() );
|
||||
TomahawkSettings::instance()->setTwitterOAuthTokenSecret( QString() );
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
TwitterPlugin::isValid()
|
||||
{
|
||||
return m_isAuthed || !m_cachedPeers.isEmpty();
|
||||
return m_isAuthed;
|
||||
}
|
||||
|
||||
const QString
|
||||
@@ -89,11 +101,11 @@ QWidget* TwitterPlugin::configWidget()
|
||||
{
|
||||
m_configWidget = new TwitterConfigWidget( this );
|
||||
|
||||
connect( m_configWidget, SIGNAL( twitterAuthed(bool) ), SLOT( configDialogAuthedSignalSlot(bool) ) );
|
||||
|
||||
return m_configWidget;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool
|
||||
TwitterPlugin::connectPlugin( bool /*startup*/ )
|
||||
{
|
||||
@@ -282,7 +294,10 @@ TwitterPlugin::friendsTimelineStatuses( const QList< QTweetStatus > &statuses )
|
||||
qDebug() << "TwitterPlugin parsed node " << node << " out of the tweet";
|
||||
|
||||
if ( status.user().screenName() == myScreenName && node == Database::instance()->dbid() )
|
||||
{
|
||||
qDebug() << "My screen name and my dbid found; ignoring";
|
||||
continue;
|
||||
}
|
||||
|
||||
QHash< QString, QVariant > peerData;
|
||||
if( m_cachedPeers.contains( status.user().screenName() ) )
|
||||
@@ -354,7 +369,10 @@ TwitterPlugin::mentionsStatuses( const QList< QTweetStatus > &statuses )
|
||||
qDebug() << "TwitterPlugin parsed node " << node << " out of the tweet";
|
||||
|
||||
if ( status.user().screenName() == myScreenName && node == Database::instance()->dbid() )
|
||||
{
|
||||
qDebug() << "My screen name and my dbid found; ignoring";
|
||||
continue;
|
||||
}
|
||||
|
||||
QHash< QString, QVariant > peerData;
|
||||
if( m_cachedPeers.contains( status.user().screenName() ) )
|
||||
|
@@ -75,6 +75,7 @@ public slots:
|
||||
}
|
||||
|
||||
private slots:
|
||||
void configDialogAuthedSignalSlot( bool authed );
|
||||
void connectAuthVerifyReply( const QTweetUser &user );
|
||||
void checkTimerFired();
|
||||
void connectTimerFired();
|
||||
|
@@ -37,25 +37,29 @@ TwitterConfigWidget::TwitterConfigWidget(SipPlugin* plugin, QWidget *parent) :
|
||||
ui->setupUi(this);
|
||||
|
||||
connect(ui->twitterAuthenticateButton, SIGNAL(pressed()),
|
||||
this, SLOT(authenticateTwitter()));
|
||||
this, SLOT(authDeauthTwitter()));
|
||||
connect(ui->twitterTweetGotTomahawkButton, SIGNAL(pressed()),
|
||||
this, SLOT(startPostGotTomahawkStatus()));
|
||||
|
||||
|
||||
TomahawkSettings* s = TomahawkSettings::instance();
|
||||
if ( s->twitterOAuthToken().isEmpty() || s->twitterOAuthTokenSecret().isEmpty() )
|
||||
if ( s->twitterOAuthToken().isEmpty() || s->twitterOAuthTokenSecret().isEmpty() || s->twitterScreenName().isEmpty() )
|
||||
{
|
||||
ui->twitterStatusLabel->setText("Status: No saved credentials");
|
||||
ui->twitterAuthenticateButton->setText( "Authenticate" );
|
||||
ui->twitterInstructionsInfoLabel->setVisible( false );
|
||||
ui->twitterTweetGotTomahawkButton->setVisible( false );
|
||||
|
||||
emit twitterAuthed( false );
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->twitterStatusLabel->setText("Status: Credentials saved");
|
||||
ui->twitterAuthenticateButton->setText( "Re-authenticate" );
|
||||
ui->twitterAuthenticateButton->setText( "De-authenticate" );
|
||||
ui->twitterInstructionsInfoLabel->setVisible( true );
|
||||
ui->twitterTweetGotTomahawkButton->setVisible( true );
|
||||
|
||||
emit twitterAuthed( true );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -65,6 +69,15 @@ TwitterConfigWidget::~TwitterConfigWidget()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void
|
||||
TwitterConfigWidget::authDeauthTwitter()
|
||||
{
|
||||
if ( ui->twitterAuthenticateButton->text() == "Authenticate" )
|
||||
authenticateTwitter();
|
||||
else
|
||||
deauthenticateTwitter();
|
||||
}
|
||||
|
||||
void
|
||||
TwitterConfigWidget::authenticateTwitter()
|
||||
{
|
||||
@@ -72,46 +85,80 @@ TwitterConfigWidget::authenticateTwitter()
|
||||
TomahawkOAuthTwitter *twitAuth = new TomahawkOAuthTwitter( this );
|
||||
twitAuth->setNetworkAccessManager( TomahawkUtils::nam() );
|
||||
twitAuth->authorizePin();
|
||||
if ( !twitAuth->oauthToken().isEmpty() && !twitAuth->oauthTokenSecret().isEmpty() )
|
||||
{
|
||||
TomahawkSettings* s = TomahawkSettings::instance();
|
||||
s->setTwitterOAuthToken( twitAuth->oauthToken() );
|
||||
s->setTwitterOAuthTokenSecret( twitAuth->oauthTokenSecret() );
|
||||
ui->twitterStatusLabel->setText("Status: Credentials saved");
|
||||
ui->twitterAuthenticateButton->setText( "Re-authenticate" );
|
||||
|
||||
ui->twitterInstructionsInfoLabel->setVisible( true );
|
||||
ui->twitterTweetGotTomahawkButton->setVisible( true );
|
||||
|
||||
TomahawkSettings::instance()->setTwitterCachedFriendsSinceId( 0 );
|
||||
TomahawkSettings::instance()->setTwitterCachedMentionsSinceId( 0 );
|
||||
m_plugin->connectPlugin( false );
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
TomahawkSettings* s = TomahawkSettings::instance();
|
||||
s->setTwitterOAuthToken( QString() );
|
||||
s->setTwitterOAuthTokenSecret( QString() );
|
||||
ui->twitterStatusLabel->setText("Status: No saved credentials");
|
||||
ui->twitterAuthenticateButton->setText( "Authenticate" );
|
||||
|
||||
ui->twitterInstructionsInfoLabel->setVisible( false );
|
||||
ui->twitterTweetGotTomahawkButton->setVisible( false );
|
||||
|
||||
QMessageBox::critical( 0, QString("Tweetin' Error"), QString("There was an error validating your authentication") );
|
||||
}
|
||||
|
||||
TomahawkSettings* s = TomahawkSettings::instance();
|
||||
s->setTwitterOAuthToken( twitAuth->oauthToken() );
|
||||
s->setTwitterOAuthTokenSecret( twitAuth->oauthTokenSecret() );
|
||||
|
||||
QTweetAccountVerifyCredentials *credVerifier = new QTweetAccountVerifyCredentials( twitAuth, this );
|
||||
connect( credVerifier, SIGNAL( parsedUser( const QTweetUser & ) ), SLOT( authenticateVerifyReply( const QTweetUser & ) ) );
|
||||
connect( credVerifier, SIGNAL( error( QTweetNetBase::ErrorCode, QString ) ), SLOT( authenticateVerifyError( QTweetNetBase::ErrorCode, QString ) ) );
|
||||
credVerifier->verify();
|
||||
}
|
||||
|
||||
void
|
||||
TwitterConfigWidget::authenticateVerifyReply( const QTweetUser &user )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
if ( user.id() == 0 )
|
||||
{
|
||||
QMessageBox::critical( 0, QString("Tweetin' Error"), QString("The credentials could not be verified.\nYou may wish to try re-authenticating.") );
|
||||
emit twitterAuthed( false );
|
||||
return;
|
||||
}
|
||||
|
||||
TomahawkSettings* s = TomahawkSettings::instance();
|
||||
s->setTwitterScreenName( user.screenName() );
|
||||
s->setTwitterCachedFriendsSinceId( 0 );
|
||||
s->setTwitterCachedMentionsSinceId( 0 );
|
||||
|
||||
ui->twitterStatusLabel->setText("Status: Credentials saved");
|
||||
ui->twitterAuthenticateButton->setText( "De-authenticate" );
|
||||
ui->twitterInstructionsInfoLabel->setVisible( true );
|
||||
ui->twitterTweetGotTomahawkButton->setVisible( true );
|
||||
|
||||
m_plugin->connectPlugin( false );
|
||||
|
||||
emit twitterAuthed( true );
|
||||
}
|
||||
|
||||
void
|
||||
TwitterConfigWidget::authenticateVerifyError( QTweetNetBase::ErrorCode code, const QString &errorMsg )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
qDebug() << "Error validating credentials, error code is " << code << ", error message is " << errorMsg;
|
||||
ui->twitterStatusLabel->setText("Status: Error validating credentials");
|
||||
emit twitterAuthed( false );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TwitterConfigWidget::deauthenticateTwitter()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
TomahawkSettings* s = TomahawkSettings::instance();
|
||||
s->setTwitterOAuthToken( QString() );
|
||||
s->setTwitterOAuthTokenSecret( QString() );
|
||||
s->setTwitterScreenName( QString() );
|
||||
|
||||
ui->twitterStatusLabel->setText("Status: No saved credentials");
|
||||
ui->twitterAuthenticateButton->setText( "Authenticate" );
|
||||
ui->twitterInstructionsInfoLabel->setVisible( false );
|
||||
ui->twitterTweetGotTomahawkButton->setVisible( false );
|
||||
|
||||
emit twitterAuthed( false );
|
||||
}
|
||||
|
||||
void
|
||||
TwitterConfigWidget::startPostGotTomahawkStatus()
|
||||
{
|
||||
qDebug() << "Posting Got Tomahawk status";
|
||||
TomahawkSettings* s = TomahawkSettings::instance();
|
||||
if ( s->twitterOAuthToken().isEmpty() || s->twitterOAuthTokenSecret().isEmpty() )
|
||||
if ( s->twitterOAuthToken().isEmpty() || s->twitterOAuthTokenSecret().isEmpty() || s->twitterScreenName().isEmpty() )
|
||||
{
|
||||
QMessageBox::critical( 0, QString("Tweetin' Error"), QString("Your saved credentials could not be loaded.\nYou may wish to try re-authenticating.") );
|
||||
emit twitterAuthed( false );
|
||||
return;
|
||||
}
|
||||
TomahawkOAuthTwitter *twitAuth = new TomahawkOAuthTwitter( this );
|
||||
@@ -130,6 +177,7 @@ TwitterConfigWidget::postGotTomahawkStatusAuthVerifyReply( const QTweetUser &use
|
||||
if ( user.id() == 0 )
|
||||
{
|
||||
QMessageBox::critical( 0, QString("Tweetin' Error"), QString("Your saved credentials could not be verified.\nYou may wish to try re-authenticating.") );
|
||||
emit twitterAuthed( false );
|
||||
return;
|
||||
}
|
||||
TomahawkSettings* s = TomahawkSettings::instance();
|
||||
|
@@ -40,14 +40,22 @@ public:
|
||||
explicit TwitterConfigWidget(SipPlugin* plugin = 0, QWidget *parent = 0);
|
||||
~TwitterConfigWidget();
|
||||
|
||||
signals:
|
||||
void twitterAuthed( bool authed );
|
||||
|
||||
private slots:
|
||||
void authenticateTwitter();
|
||||
void authDeauthTwitter();
|
||||
void startPostGotTomahawkStatus();
|
||||
void authenticateVerifyReply( const QTweetUser &user );
|
||||
void authenticateVerifyError( QTweetNetBase::ErrorCode code, const QString &errorMsg );
|
||||
void postGotTomahawkStatusAuthVerifyReply( const QTweetUser &user );
|
||||
void postGotTomahawkStatusUpdateReply( const QTweetStatus &status );
|
||||
void postGotTomahawkStatusUpdateError( QTweetNetBase::ErrorCode, const QString &errorMsg );
|
||||
|
||||
private:
|
||||
void authenticateTwitter();
|
||||
void deauthenticateTwitter();
|
||||
|
||||
Ui::TwitterConfigWidget *ui;
|
||||
SipPlugin *m_plugin;
|
||||
};
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#include "tomahawkoauthtwitter.h"
|
||||
#include <QInputDialog>
|
||||
#include <QDebug>
|
||||
|
||||
TomahawkOAuthTwitter::TomahawkOAuthTwitter( QObject* parent )
|
||||
: OAuthTwitter( parent )
|
||||
@@ -7,7 +8,8 @@ TomahawkOAuthTwitter::TomahawkOAuthTwitter( QObject* parent )
|
||||
}
|
||||
|
||||
|
||||
int TomahawkOAuthTwitter::authorizationWidget()
|
||||
int
|
||||
TomahawkOAuthTwitter::authorizationWidget()
|
||||
{
|
||||
bool ok;
|
||||
int i = QInputDialog::getInt(0, QString( "Twitter PIN" ), QString( "After authenticating on Twitter's web site,\nenter the displayed PIN number here:" ), 0, 0, 2147483647, 1, &ok);
|
||||
@@ -16,3 +18,11 @@ int TomahawkOAuthTwitter::authorizationWidget()
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
TomahawkOAuthTwitter::error()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
setOAuthToken( QString().toLatin1() );
|
||||
setOAuthTokenSecret( QString().toLatin1() );
|
||||
}
|
||||
|
@@ -16,6 +16,9 @@ public:
|
||||
|
||||
protected:
|
||||
virtual int authorizationWidget();
|
||||
|
||||
private slots:
|
||||
void error();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user