mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-12 09:04:33 +02:00
Update Hatchet account to use new API.
This commit is contained in:
@@ -263,7 +263,7 @@ HatchetAccount::fetchAccessTokens( const QString& type )
|
|||||||
tLog() << "Auth token has expired, but may still be valid on the server";
|
tLog() << "Auth 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 + "?authtoken=" + authToken() ) );
|
QNetworkRequest req( QUrl( c_accessTokenServer + "/tokens/" + type + "?username=" + username() + "&authtoken=" + authToken() ) );
|
||||||
|
|
||||||
QNetworkReply* reply = Tomahawk::Utils::nam()->get( req );
|
QNetworkReply* reply = Tomahawk::Utils::nam()->get( req );
|
||||||
|
|
||||||
@@ -287,18 +287,24 @@ HatchetAccount::onPasswordLoginFinished( QNetworkReply* reply, const QString& us
|
|||||||
if ( !ok )
|
if ( !ok )
|
||||||
{
|
{
|
||||||
tLog() << Q_FUNC_INFO << "Error getting parsed reply from auth server";
|
tLog() << Q_FUNC_INFO << "Error getting parsed reply from auth server";
|
||||||
emit authError( "An error occurred reading the reply from the server", statusCode );
|
emit authError( "An error occurred reading the reply from the authentication server", statusCode );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if ( statusCode >= 500 )
|
||||||
if ( !resp.value( "error" ).toString().isEmpty() )
|
|
||||||
{
|
{
|
||||||
tLog() << Q_FUNC_INFO << "Auth server returned an error";
|
tLog() << Q_FUNC_INFO << "Encountered internal error from auth server, cannot continue";
|
||||||
emit authError( resp.value( "error" ).toString(), statusCode );
|
emit authError( "The authentication server reported an internal error, please try again later", statusCode );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ( statusCode >= 400 )
|
||||||
|
{
|
||||||
|
QString errString = resp.value( "result" ).toMap().value( "errorinfo" ).toMap().value( "description" ).toString();
|
||||||
|
tLog() << Q_FUNC_INFO << "An error was returned from the authentication server: " << errString;
|
||||||
|
emit authError( errString, statusCode );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString nonce = resp.value( "data" ).toMap().value( "nonce" ).toString();
|
const QString nonce = resp.value( "result" ).toMap().value( "nonce" ).toString();
|
||||||
if ( nonce != m_uuid )
|
if ( nonce != m_uuid )
|
||||||
{
|
{
|
||||||
tLog() << Q_FUNC_INFO << "Auth server nonce value does not match!";
|
tLog() << Q_FUNC_INFO << "Auth server nonce value does not match!";
|
||||||
@@ -306,8 +312,8 @@ HatchetAccount::onPasswordLoginFinished( QNetworkReply* reply, const QString& us
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QByteArray authenticationToken = resp.value( "data" ).toMap().value( "token" ).toByteArray();
|
const QByteArray authenticationToken = resp.value( "result" ).toMap().value( "token" ).toByteArray();
|
||||||
uint expiration = resp.value( "data" ).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;
|
||||||
@@ -330,6 +336,7 @@ HatchetAccount::onFetchAccessTokensFinished()
|
|||||||
tLog() << Q_FUNC_INFO;
|
tLog() << Q_FUNC_INFO;
|
||||||
QNetworkReply* reply = qobject_cast< QNetworkReply* >( sender() );
|
QNetworkReply* reply = qobject_cast< QNetworkReply* >( sender() );
|
||||||
Q_ASSERT( reply );
|
Q_ASSERT( reply );
|
||||||
|
|
||||||
bool ok;
|
bool ok;
|
||||||
int statusCode = reply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).toInt( &ok );
|
int statusCode = reply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).toInt( &ok );
|
||||||
if ( !ok )
|
if ( !ok )
|
||||||
@@ -339,12 +346,23 @@ HatchetAccount::onFetchAccessTokensFinished()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const QVariantMap resp = parseReply( reply, ok );
|
const QVariantMap resp = parseReply( reply, ok );
|
||||||
if ( !ok || !resp.value( "error" ).toString().isEmpty() )
|
if ( !ok )
|
||||||
{
|
{
|
||||||
tLog() << Q_FUNC_INFO << "Auth server returned an error";
|
tLog() << Q_FUNC_INFO << "Error getting parsed reply from auth server";
|
||||||
if ( ok )
|
emit authError( "An error occurred reading the reply from the authentication server", statusCode );
|
||||||
emit authError( resp.value( "error" ).toString(), statusCode );
|
return;
|
||||||
deauthenticate();
|
}
|
||||||
|
if ( statusCode >= 500 )
|
||||||
|
{
|
||||||
|
tLog() << Q_FUNC_INFO << "Encountered internal error from auth server, cannot continue";
|
||||||
|
emit authError( "The authentication server reported an internal error, please try again later", statusCode );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ( statusCode >= 400 )
|
||||||
|
{
|
||||||
|
QString errString = resp.value( "result" ).toMap().value( "errorinfo" ).toMap().value( "description" ).toString();
|
||||||
|
tLog() << Q_FUNC_INFO << "An error was returned from the authentication server: " << errString;
|
||||||
|
emit authError( errString, statusCode );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,7 +371,7 @@ HatchetAccount::onFetchAccessTokensFinished()
|
|||||||
|
|
||||||
tDebug() << Q_FUNC_INFO << "resp: " << resp;
|
tDebug() << Q_FUNC_INFO << "resp: " << resp;
|
||||||
|
|
||||||
foreach( QVariant tokenVariant, resp[ "data" ].toMap()[ "tokens" ].toList() )
|
foreach( QVariant tokenVariant, resp[ "result" ].toMap()[ "tokens" ].toList() )
|
||||||
{
|
{
|
||||||
QVariantMap tokenMap = tokenVariant.toMap();
|
QVariantMap tokenMap = tokenVariant.toMap();
|
||||||
QString tokenTypeName = tokenMap[ "type" ].toString() + "tokens";
|
QString tokenTypeName = tokenMap[ "type" ].toString() + "tokens";
|
||||||
@@ -399,7 +417,7 @@ HatchetAccount::parseReply( QNetworkReply* reply, bool& okRet ) const
|
|||||||
|
|
||||||
bool ok;
|
bool ok;
|
||||||
int statusCode = reply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).toInt( &ok );
|
int statusCode = reply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).toInt( &ok );
|
||||||
if ( reply->error() != QNetworkReply::NoError && statusCode != 400 && statusCode != 500 )
|
if ( reply->error() != QNetworkReply::NoError && statusCode < 400 )
|
||||||
{
|
{
|
||||||
tLog() << Q_FUNC_INFO << "Network error in command:" << reply->error() << reply->errorString();
|
tLog() << Q_FUNC_INFO << "Network error in command:" << reply->error() << reply->errorString();
|
||||||
okRet = false;
|
okRet = false;
|
||||||
@@ -416,9 +434,9 @@ HatchetAccount::parseReply( QNetworkReply* reply, bool& okRet ) const
|
|||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !resp.value( "error", "" ).toString().isEmpty() )
|
if ( statusCode >= 400 )
|
||||||
{
|
{
|
||||||
tLog() << "Error from tomahawk server response, or in parsing from json:" << resp.value( "error" ).toString() << resp;
|
tDebug() << "Error from tomahawk server response, or in parsing from json:" << resp.value( "error" ).toString() << resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
tDebug() << Q_FUNC_INFO << "Got keys" << resp.keys();
|
tDebug() << Q_FUNC_INFO << "Got keys" << resp.keys();
|
||||||
|
Reference in New Issue
Block a user