mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-22 21:54:00 +02:00
Fix some mandella API changes
This commit is contained in:
@@ -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:
|
||||
|
@@ -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();
|
||||
|
@@ -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 );
|
||||
|
||||
|
@@ -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
|
||||
{
|
||||
|
Reference in New Issue
Block a user