Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove trailing slash for LastFM auth URLs to avoid a redirect. #6429

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/internet/lastfm/lastfmservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <QMenu>
#include <QMessageBox>
#include <QSettings>
#include <QTextCodec>
#include <QUrlQuery>

#ifdef HAVE_LIBLASTFM1
Expand Down Expand Up @@ -76,7 +77,7 @@ const char* LastFMService::kAudioscrobblerClientId = "tng";
const char* LastFMService::kApiKey = "75d20fb472be99275392aefa2760ea09";
const char* LastFMService::kSecret = "d3072b60ae626be12be69448f5c46e70";
const char* LastFMService::kAuthLoginUrl =
"https://www.last.fm/api/auth/?api_key=%1&token=%2";
"https://www.last.fm/api/auth?api_key=%1&token=%2";

LastFMService::LastFMService(Application* app, QObject* parent)
: Scrobbler(parent),
Expand Down Expand Up @@ -146,7 +147,7 @@ QByteArray SignApiRequest(QList<QPair<QString, QString>> params) {
} // namespace

void LastFMService::Authenticate() {
QUrl url("https://www.last.fm/api/auth/");
QUrl url("https://www.last.fm/api/auth");

LocalRedirectServer* server = new LocalRedirectServer(this);
server->Listen();
Expand Down Expand Up @@ -174,20 +175,28 @@ void LastFMService::Authenticate() {
NewClosure(reply, SIGNAL(finished()), this, SLOT(AuthenticateReplyFinished(QNetworkReply*)), reply);
});

qLog(Debug) << "auth URL:" << url.toString();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the logging for non-errors here and below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found these very helpful when trying to debug my authentication problem. Note that In case openUrl fails the URL is also being logged. This is also happening just once during the auth phase, so it's not adding undue log volume or anything.

As I said, it was helpful to see what my browser was returning for these URLs and they might help someone to not have to read the code.

Could you expand why you think they should be removed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid logging potentially sensitive data, e.g., tokens, oauth codes, etc. as people often post full logs here.

It's easy enough to add this back in later when developing.

if (!QDesktopServices::openUrl(url)) {
QMessageBox box(QMessageBox::NoIcon, tr("Last.fm Authentication"), tr("Please open this URL in your browser: <a href=\"%1\">%1</a>").arg(url.toString()), QMessageBox::Ok);
box.setTextFormat(Qt::RichText);
qLog(Debug) << "Last.fm authentication URL: " << url.toString();
box.exec();
}
}

void LastFMService::AuthenticateReplyFinished(QNetworkReply* reply) {
reply->deleteLater();

if (reply->error() != QNetworkReply::NoError) {
qLog(Debug) << "request error:" << reply->errorString();
}

const QByteArray resp = reply->readAll();
QTextCodec* codec = QTextCodec::codecForName("UTF-8");
qLog(Debug) << "auth reply:" << codec->toUnicode(resp);

// Parse the reply
lastfm::XmlQuery lfm(lastfm::compat::EmptyXmlQuery());
if (lastfm::compat::ParseQuery(reply->readAll(), &lfm)) {
if (!resp.isEmpty() && lastfm::compat::ParseQuery(resp, &lfm)) {
lastfm::ws::Username = lfm["session"]["name"].text();
lastfm::ws::SessionKey = lfm["session"]["key"].text();
QString subscribed = lfm["session"]["subscriber"].text();
Expand Down