From 1adefb3e5d3b463de1e504c894f8bab03ce52b6c Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Tue, 10 Dec 2013 16:06:00 -0500 Subject: [PATCH] Fix some mandella API changes --- CMakeLists.txt | 2 +- .../hatchet/account/HatchetAccount.cpp | 35 +++++++++++-------- src/accounts/hatchet/account/HatchetAccount.h | 4 +-- .../hatchet/account/HatchetAccountConfig.cpp | 2 +- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 297be193a..91365aa73 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ CMAKE_MINIMUM_REQUIRED( VERSION 2.8.6 ) SET( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules" ) 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) # TODO: diff --git a/src/accounts/hatchet/account/HatchetAccount.cpp b/src/accounts/hatchet/account/HatchetAccount.cpp index 6451acaf9..145caad9d 100644 --- a/src/accounts/hatchet/account/HatchetAccount.cpp +++ b/src/accounts/hatchet/account/HatchetAccount.cpp @@ -132,9 +132,9 @@ HatchetAccount::authenticate() if ( connectionState() == Connected ) 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() ) sipPlugin()->connectPlugin(); setAccountFriendlyName( username() ); @@ -201,7 +201,7 @@ HatchetAccount::icon() const bool HatchetAccount::isAuthenticated() const { - return credentials().contains( "authtoken" ); + return credentials().contains( "refresh_token" ); } @@ -213,14 +213,14 @@ HatchetAccount::username() const QByteArray -HatchetAccount::authToken() const +HatchetAccount::refreshToken() const { - return credentials().value( "authtoken" ).toByteArray(); + return credentials().value( "refresh_token" ).toByteArray(); } uint -HatchetAccount::authTokenExpiration() const +HatchetAccount::refreshTokenExpiration() const { bool ok; return credentials().value( "expiration" ).toUInt( &ok ); @@ -262,17 +262,17 @@ HatchetAccount::loginWithPassword( const QString& username, const QString& passw void 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; } - if ( authTokenExpiration() < ( QDateTime::currentMSecsSinceEpoch() / 1000 ) ) - tLog() << "Auth token has expired, but may still be valid on the server"; + if ( refreshTokenExpiration() < ( QDateTime::currentMSecsSinceEpoch() / 1000 ) ) + tLog() << "Refresh token has expired, but may still be valid on the server"; 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 ); @@ -321,17 +321,17 @@ HatchetAccount::onPasswordLoginFinished( QNetworkReply* reply, const QString& us 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 ); QVariantHash creds = credentials(); creds[ "username" ] = username; - creds[ "authtoken" ] = authenticationToken; + creds[ "refresh_token" ] = refreshTokenBytes; creds[ "expiration" ] = expiration; setCredentials( creds ); syncConfig(); - if ( !authenticationToken.isEmpty() ) + if ( !refreshTokenBytes.isEmpty() ) { if ( sipPlugin() ) sipPlugin()->connectPlugin(); @@ -380,6 +380,13 @@ HatchetAccount::onFetchAccessTokensFinished() 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() ) { QVariantMap tokenMap = tokenVariant.toMap(); diff --git a/src/accounts/hatchet/account/HatchetAccount.h b/src/accounts/hatchet/account/HatchetAccount.h index 220775351..e476e5833 100644 --- a/src/accounts/hatchet/account/HatchetAccount.h +++ b/src/accounts/hatchet/account/HatchetAccount.h @@ -103,8 +103,8 @@ private slots: void authUrlDiscovered( Tomahawk::Accounts::HatchetAccount::Service service, const QString& authUrl ); private: - QByteArray authToken() const; - uint authTokenExpiration() const; + QByteArray refreshToken() const; + uint refreshTokenExpiration() const; void loginWithPassword( const QString& username, const QString& password, const QString &otp ); diff --git a/src/accounts/hatchet/account/HatchetAccountConfig.cpp b/src/accounts/hatchet/account/HatchetAccountConfig.cpp index acee9cbea..17b2fda52 100644 --- a/src/accounts/hatchet/account/HatchetAccountConfig.cpp +++ b/src/accounts/hatchet/account/HatchetAccountConfig.cpp @@ -58,7 +58,7 @@ HatchetAccountConfig::HatchetAccountConfig( HatchetAccount* account ) connect( m_account, SIGNAL( deauthenticated() ), this, SLOT( showLoggedOut() ) ); connect( m_account, SIGNAL( accessTokensFetched() ), this, SLOT( accountInfoUpdated() ) ); - if ( !m_account->authToken().isEmpty() ) + if ( !m_account->refreshToken().isEmpty() ) accountInfoUpdated(); else {