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();
|
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
|
bool
|
||||||
TwitterPlugin::isValid()
|
TwitterPlugin::isValid()
|
||||||
{
|
{
|
||||||
return m_isAuthed || !m_cachedPeers.isEmpty();
|
return m_isAuthed;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString
|
const QString
|
||||||
@@ -89,11 +101,11 @@ QWidget* TwitterPlugin::configWidget()
|
|||||||
{
|
{
|
||||||
m_configWidget = new TwitterConfigWidget( this );
|
m_configWidget = new TwitterConfigWidget( this );
|
||||||
|
|
||||||
|
connect( m_configWidget, SIGNAL( twitterAuthed(bool) ), SLOT( configDialogAuthedSignalSlot(bool) ) );
|
||||||
|
|
||||||
return m_configWidget;
|
return m_configWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
TwitterPlugin::connectPlugin( bool /*startup*/ )
|
TwitterPlugin::connectPlugin( bool /*startup*/ )
|
||||||
{
|
{
|
||||||
@@ -282,7 +294,10 @@ TwitterPlugin::friendsTimelineStatuses( const QList< QTweetStatus > &statuses )
|
|||||||
qDebug() << "TwitterPlugin parsed node " << node << " out of the tweet";
|
qDebug() << "TwitterPlugin parsed node " << node << " out of the tweet";
|
||||||
|
|
||||||
if ( status.user().screenName() == myScreenName && node == Database::instance()->dbid() )
|
if ( status.user().screenName() == myScreenName && node == Database::instance()->dbid() )
|
||||||
|
{
|
||||||
|
qDebug() << "My screen name and my dbid found; ignoring";
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
QHash< QString, QVariant > peerData;
|
QHash< QString, QVariant > peerData;
|
||||||
if( m_cachedPeers.contains( status.user().screenName() ) )
|
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";
|
qDebug() << "TwitterPlugin parsed node " << node << " out of the tweet";
|
||||||
|
|
||||||
if ( status.user().screenName() == myScreenName && node == Database::instance()->dbid() )
|
if ( status.user().screenName() == myScreenName && node == Database::instance()->dbid() )
|
||||||
|
{
|
||||||
|
qDebug() << "My screen name and my dbid found; ignoring";
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
QHash< QString, QVariant > peerData;
|
QHash< QString, QVariant > peerData;
|
||||||
if( m_cachedPeers.contains( status.user().screenName() ) )
|
if( m_cachedPeers.contains( status.user().screenName() ) )
|
||||||
|
@@ -75,6 +75,7 @@ public slots:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void configDialogAuthedSignalSlot( bool authed );
|
||||||
void connectAuthVerifyReply( const QTweetUser &user );
|
void connectAuthVerifyReply( const QTweetUser &user );
|
||||||
void checkTimerFired();
|
void checkTimerFired();
|
||||||
void connectTimerFired();
|
void connectTimerFired();
|
||||||
|
@@ -37,25 +37,29 @@ TwitterConfigWidget::TwitterConfigWidget(SipPlugin* plugin, QWidget *parent) :
|
|||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
connect(ui->twitterAuthenticateButton, SIGNAL(pressed()),
|
connect(ui->twitterAuthenticateButton, SIGNAL(pressed()),
|
||||||
this, SLOT(authenticateTwitter()));
|
this, SLOT(authDeauthTwitter()));
|
||||||
connect(ui->twitterTweetGotTomahawkButton, SIGNAL(pressed()),
|
connect(ui->twitterTweetGotTomahawkButton, SIGNAL(pressed()),
|
||||||
this, SLOT(startPostGotTomahawkStatus()));
|
this, SLOT(startPostGotTomahawkStatus()));
|
||||||
|
|
||||||
|
|
||||||
TomahawkSettings* s = TomahawkSettings::instance();
|
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->twitterStatusLabel->setText("Status: No saved credentials");
|
||||||
ui->twitterAuthenticateButton->setText( "Authenticate" );
|
ui->twitterAuthenticateButton->setText( "Authenticate" );
|
||||||
ui->twitterInstructionsInfoLabel->setVisible( false );
|
ui->twitterInstructionsInfoLabel->setVisible( false );
|
||||||
ui->twitterTweetGotTomahawkButton->setVisible( false );
|
ui->twitterTweetGotTomahawkButton->setVisible( false );
|
||||||
|
|
||||||
|
emit twitterAuthed( false );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ui->twitterStatusLabel->setText("Status: Credentials saved");
|
ui->twitterStatusLabel->setText("Status: Credentials saved");
|
||||||
ui->twitterAuthenticateButton->setText( "Re-authenticate" );
|
ui->twitterAuthenticateButton->setText( "De-authenticate" );
|
||||||
ui->twitterInstructionsInfoLabel->setVisible( true );
|
ui->twitterInstructionsInfoLabel->setVisible( true );
|
||||||
ui->twitterTweetGotTomahawkButton->setVisible( true );
|
ui->twitterTweetGotTomahawkButton->setVisible( true );
|
||||||
|
|
||||||
|
emit twitterAuthed( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -65,6 +69,15 @@ TwitterConfigWidget::~TwitterConfigWidget()
|
|||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TwitterConfigWidget::authDeauthTwitter()
|
||||||
|
{
|
||||||
|
if ( ui->twitterAuthenticateButton->text() == "Authenticate" )
|
||||||
|
authenticateTwitter();
|
||||||
|
else
|
||||||
|
deauthenticateTwitter();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TwitterConfigWidget::authenticateTwitter()
|
TwitterConfigWidget::authenticateTwitter()
|
||||||
{
|
{
|
||||||
@@ -72,46 +85,80 @@ TwitterConfigWidget::authenticateTwitter()
|
|||||||
TomahawkOAuthTwitter *twitAuth = new TomahawkOAuthTwitter( this );
|
TomahawkOAuthTwitter *twitAuth = new TomahawkOAuthTwitter( this );
|
||||||
twitAuth->setNetworkAccessManager( TomahawkUtils::nam() );
|
twitAuth->setNetworkAccessManager( TomahawkUtils::nam() );
|
||||||
twitAuth->authorizePin();
|
twitAuth->authorizePin();
|
||||||
if ( !twitAuth->oauthToken().isEmpty() && !twitAuth->oauthTokenSecret().isEmpty() )
|
|
||||||
{
|
TomahawkSettings* s = TomahawkSettings::instance();
|
||||||
TomahawkSettings* s = TomahawkSettings::instance();
|
s->setTwitterOAuthToken( twitAuth->oauthToken() );
|
||||||
s->setTwitterOAuthToken( twitAuth->oauthToken() );
|
s->setTwitterOAuthTokenSecret( twitAuth->oauthTokenSecret() );
|
||||||
s->setTwitterOAuthTokenSecret( twitAuth->oauthTokenSecret() );
|
|
||||||
ui->twitterStatusLabel->setText("Status: Credentials saved");
|
QTweetAccountVerifyCredentials *credVerifier = new QTweetAccountVerifyCredentials( twitAuth, this );
|
||||||
ui->twitterAuthenticateButton->setText( "Re-authenticate" );
|
connect( credVerifier, SIGNAL( parsedUser( const QTweetUser & ) ), SLOT( authenticateVerifyReply( const QTweetUser & ) ) );
|
||||||
|
connect( credVerifier, SIGNAL( error( QTweetNetBase::ErrorCode, QString ) ), SLOT( authenticateVerifyError( QTweetNetBase::ErrorCode, QString ) ) );
|
||||||
ui->twitterInstructionsInfoLabel->setVisible( true );
|
credVerifier->verify();
|
||||||
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") );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
void
|
||||||
TwitterConfigWidget::startPostGotTomahawkStatus()
|
TwitterConfigWidget::startPostGotTomahawkStatus()
|
||||||
{
|
{
|
||||||
qDebug() << "Posting Got Tomahawk status";
|
qDebug() << "Posting Got Tomahawk status";
|
||||||
TomahawkSettings* s = TomahawkSettings::instance();
|
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.") );
|
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;
|
return;
|
||||||
}
|
}
|
||||||
TomahawkOAuthTwitter *twitAuth = new TomahawkOAuthTwitter( this );
|
TomahawkOAuthTwitter *twitAuth = new TomahawkOAuthTwitter( this );
|
||||||
@@ -130,6 +177,7 @@ TwitterConfigWidget::postGotTomahawkStatusAuthVerifyReply( const QTweetUser &use
|
|||||||
if ( user.id() == 0 )
|
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.") );
|
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;
|
return;
|
||||||
}
|
}
|
||||||
TomahawkSettings* s = TomahawkSettings::instance();
|
TomahawkSettings* s = TomahawkSettings::instance();
|
||||||
|
@@ -40,14 +40,22 @@ public:
|
|||||||
explicit TwitterConfigWidget(SipPlugin* plugin = 0, QWidget *parent = 0);
|
explicit TwitterConfigWidget(SipPlugin* plugin = 0, QWidget *parent = 0);
|
||||||
~TwitterConfigWidget();
|
~TwitterConfigWidget();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void twitterAuthed( bool authed );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void authenticateTwitter();
|
void authDeauthTwitter();
|
||||||
void startPostGotTomahawkStatus();
|
void startPostGotTomahawkStatus();
|
||||||
|
void authenticateVerifyReply( const QTweetUser &user );
|
||||||
|
void authenticateVerifyError( QTweetNetBase::ErrorCode code, const QString &errorMsg );
|
||||||
void postGotTomahawkStatusAuthVerifyReply( const QTweetUser &user );
|
void postGotTomahawkStatusAuthVerifyReply( const QTweetUser &user );
|
||||||
void postGotTomahawkStatusUpdateReply( const QTweetStatus &status );
|
void postGotTomahawkStatusUpdateReply( const QTweetStatus &status );
|
||||||
void postGotTomahawkStatusUpdateError( QTweetNetBase::ErrorCode, const QString &errorMsg );
|
void postGotTomahawkStatusUpdateError( QTweetNetBase::ErrorCode, const QString &errorMsg );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void authenticateTwitter();
|
||||||
|
void deauthenticateTwitter();
|
||||||
|
|
||||||
Ui::TwitterConfigWidget *ui;
|
Ui::TwitterConfigWidget *ui;
|
||||||
SipPlugin *m_plugin;
|
SipPlugin *m_plugin;
|
||||||
};
|
};
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
#include "tomahawkoauthtwitter.h"
|
#include "tomahawkoauthtwitter.h"
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
TomahawkOAuthTwitter::TomahawkOAuthTwitter( QObject* parent )
|
TomahawkOAuthTwitter::TomahawkOAuthTwitter( QObject* parent )
|
||||||
: OAuthTwitter( parent )
|
: OAuthTwitter( parent )
|
||||||
@@ -7,7 +8,8 @@ TomahawkOAuthTwitter::TomahawkOAuthTwitter( QObject* parent )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int TomahawkOAuthTwitter::authorizationWidget()
|
int
|
||||||
|
TomahawkOAuthTwitter::authorizationWidget()
|
||||||
{
|
{
|
||||||
bool ok;
|
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);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TomahawkOAuthTwitter::error()
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
setOAuthToken( QString().toLatin1() );
|
||||||
|
setOAuthTokenSecret( QString().toLatin1() );
|
||||||
|
}
|
||||||
|
@@ -16,6 +16,9 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual int authorizationWidget();
|
virtual int authorizationWidget();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void error();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user