1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-23 06:02:53 +02:00

Fix some mandella API changes

This commit is contained in:
Jeff Mitchell
2013-12-10 16:06:00 -05:00
parent aff4e329c1
commit 1adefb3e5d
4 changed files with 25 additions and 18 deletions

View File

@@ -3,7 +3,7 @@ CMAKE_MINIMUM_REQUIRED( VERSION 2.8.6 )
SET( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules" ) SET( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules" )
CMAKE_POLICY(SET CMP0017 NEW) CMAKE_POLICY(SET CMP0017 NEW)
IF ( CMAKE_VERSION VERSION_EQUAL 2.8.12 OR CMAKE_VERSION GREATER 2.8.12 ) IF ( CMAKE_VERSION VERSION_EQUAL 2.8.12 OR CMAKE_VERSION VERSION_GREATER 2.8.12 )
CMAKE_POLICY(SET CMP0022 NEW) CMAKE_POLICY(SET CMP0022 NEW)
# TODO: # TODO:

View File

@@ -132,9 +132,9 @@ HatchetAccount::authenticate()
if ( connectionState() == Connected ) if ( connectionState() == Connected )
return; return;
if ( !authToken().isEmpty() ) if ( !refreshToken().isEmpty() )
{ {
qDebug() << "Have saved credentials with auth token:" << authToken(); qDebug() << "Have saved credentials with refresh token:" << refreshToken();
if ( sipPlugin() ) if ( sipPlugin() )
sipPlugin()->connectPlugin(); sipPlugin()->connectPlugin();
setAccountFriendlyName( username() ); setAccountFriendlyName( username() );
@@ -201,7 +201,7 @@ HatchetAccount::icon() const
bool bool
HatchetAccount::isAuthenticated() const HatchetAccount::isAuthenticated() const
{ {
return credentials().contains( "authtoken" ); return credentials().contains( "refresh_token" );
} }
@@ -213,14 +213,14 @@ HatchetAccount::username() const
QByteArray QByteArray
HatchetAccount::authToken() const HatchetAccount::refreshToken() const
{ {
return credentials().value( "authtoken" ).toByteArray(); return credentials().value( "refresh_token" ).toByteArray();
} }
uint uint
HatchetAccount::authTokenExpiration() const HatchetAccount::refreshTokenExpiration() const
{ {
bool ok; bool ok;
return credentials().value( "expiration" ).toUInt( &ok ); return credentials().value( "expiration" ).toUInt( &ok );
@@ -262,17 +262,17 @@ HatchetAccount::loginWithPassword( const QString& username, const QString& passw
void void
HatchetAccount::fetchAccessTokens( const QString& type ) HatchetAccount::fetchAccessTokens( const QString& type )
{ {
if ( username().isEmpty() || authToken().isEmpty() ) if ( username().isEmpty() || refreshToken().isEmpty() )
{ {
tLog() << "No authToken, not logging in"; tLog() << "No refresh token, not logging in";
return; return;
} }
if ( authTokenExpiration() < ( QDateTime::currentMSecsSinceEpoch() / 1000 ) ) if ( refreshTokenExpiration() < ( QDateTime::currentMSecsSinceEpoch() / 1000 ) )
tLog() << "Auth token has expired, but may still be valid on the server"; tLog() << "Refresh token has expired, but may still be valid on the server";
tLog() << "Fetching access tokens"; tLog() << "Fetching access tokens";
QNetworkRequest req( QUrl( c_accessTokenServer + "/tokens/" + type + "?username=" + username() + "&authtoken=" + authToken() ) ); QNetworkRequest req( QUrl( c_accessTokenServer + "/tokens/" + type + "?username=" + username() + "&refresh_token=" + refreshToken() ) );
QNetworkReply* reply = Tomahawk::Utils::nam()->get( req ); QNetworkReply* reply = Tomahawk::Utils::nam()->get( req );
@@ -321,17 +321,17 @@ HatchetAccount::onPasswordLoginFinished( QNetworkReply* reply, const QString& us
return; return;
} }
const QByteArray authenticationToken = resp.value( "result" ).toMap().value( "token" ).toByteArray(); const QByteArray refreshTokenBytes = resp.value( "result" ).toMap().value( "refresh_token" ).toByteArray();
uint expiration = resp.value( "result" ).toMap().value( "expiration" ).toUInt( &ok ); uint expiration = resp.value( "result" ).toMap().value( "expiration" ).toUInt( &ok );
QVariantHash creds = credentials(); QVariantHash creds = credentials();
creds[ "username" ] = username; creds[ "username" ] = username;
creds[ "authtoken" ] = authenticationToken; creds[ "refresh_token" ] = refreshTokenBytes;
creds[ "expiration" ] = expiration; creds[ "expiration" ] = expiration;
setCredentials( creds ); setCredentials( creds );
syncConfig(); syncConfig();
if ( !authenticationToken.isEmpty() ) if ( !refreshTokenBytes.isEmpty() )
{ {
if ( sipPlugin() ) if ( sipPlugin() )
sipPlugin()->connectPlugin(); sipPlugin()->connectPlugin();
@@ -380,6 +380,13 @@ HatchetAccount::onFetchAccessTokensFinished()
tDebug() << Q_FUNC_INFO << "resp: " << resp; tDebug() << Q_FUNC_INFO << "resp: " << resp;
if ( resp[ "result" ].toMap().contains( "refresh_token_expiration" ) )
{
bool ok;
uint expiration = resp.value( "result" ).toMap().value( "refresh_token_expiration" ).toUInt( &ok );
creds[ "expiration" ] = expiration;
}
foreach( QVariant tokenVariant, resp[ "result" ].toMap()[ "tokens" ].toList() ) foreach( QVariant tokenVariant, resp[ "result" ].toMap()[ "tokens" ].toList() )
{ {
QVariantMap tokenMap = tokenVariant.toMap(); QVariantMap tokenMap = tokenVariant.toMap();

View File

@@ -103,8 +103,8 @@ private slots:
void authUrlDiscovered( Tomahawk::Accounts::HatchetAccount::Service service, const QString& authUrl ); void authUrlDiscovered( Tomahawk::Accounts::HatchetAccount::Service service, const QString& authUrl );
private: private:
QByteArray authToken() const; QByteArray refreshToken() const;
uint authTokenExpiration() const; uint refreshTokenExpiration() const;
void loginWithPassword( const QString& username, const QString& password, const QString &otp ); void loginWithPassword( const QString& username, const QString& password, const QString &otp );

View File

@@ -58,7 +58,7 @@ HatchetAccountConfig::HatchetAccountConfig( HatchetAccount* account )
connect( m_account, SIGNAL( deauthenticated() ), this, SLOT( showLoggedOut() ) ); connect( m_account, SIGNAL( deauthenticated() ), this, SLOT( showLoggedOut() ) );
connect( m_account, SIGNAL( accessTokensFetched() ), this, SLOT( accountInfoUpdated() ) ); connect( m_account, SIGNAL( accessTokensFetched() ), this, SLOT( accountInfoUpdated() ) );
if ( !m_account->authToken().isEmpty() ) if ( !m_account->refreshToken().isEmpty() )
accountInfoUpdated(); accountInfoUpdated();
else else
{ {