mirror of
https://github.com/strawberrymusicplayer/strawberry
synced 2024-12-16 10:38:53 +01:00
Subsonic: Fix auth method for URL handler
This commit is contained in:
parent
3137652280
commit
f4f005cdd6
@ -57,7 +57,25 @@ SubsonicBaseRequest::SubsonicBaseRequest(SubsonicService *service, QObject *pare
|
||||
|
||||
}
|
||||
|
||||
QUrl SubsonicBaseRequest::CreateUrl(const QString &ressource_name, const QList<Param> ¶ms_provided) const {
|
||||
void SubsonicBaseRequest::AddPasswordToParams(ParamList ¶ms, const SubsonicSettingsPage::AuthMethod auth_method, const QString &password) {
|
||||
|
||||
if (password.isEmpty()) return;
|
||||
|
||||
if (auth_method == SubsonicSettingsPage::AuthMethod_Hex) {
|
||||
params << Param("p", QString("enc:" + password.toUtf8().toHex()));
|
||||
}
|
||||
else {
|
||||
const QString salt = Utilities::CryptographicRandomString(20);
|
||||
QCryptographicHash md5(QCryptographicHash::Md5);
|
||||
md5.addData(password.toUtf8());
|
||||
md5.addData(salt.toUtf8());
|
||||
params << Param("s", salt);
|
||||
params << Param("t", md5.result().toHex());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QUrl SubsonicBaseRequest::CreateUrl(const QString &ressource_name, const ParamList ¶ms_provided) const {
|
||||
|
||||
ParamList params = ParamList() << params_provided
|
||||
<< Param("c", client_name())
|
||||
@ -65,17 +83,7 @@ QUrl SubsonicBaseRequest::CreateUrl(const QString &ressource_name, const QList<P
|
||||
<< Param("f", "json")
|
||||
<< Param("u", username());
|
||||
|
||||
if (service_->auth_method() == SubsonicSettingsPage::AuthMethod_Hex) {
|
||||
params << Param("p", QString("enc:" + password().toUtf8().toHex()));
|
||||
}
|
||||
else {
|
||||
const QString salt = Utilities::CryptographicRandomString(20);
|
||||
QCryptographicHash md5(QCryptographicHash::Md5);
|
||||
md5.addData(password().toUtf8());
|
||||
md5.addData(salt.toUtf8());
|
||||
params << Param("s", salt);
|
||||
params << Param("t", md5.result().toHex());
|
||||
}
|
||||
AddPasswordToParams(params, auth_method(), password());
|
||||
|
||||
QUrlQuery url_query;
|
||||
for (const Param ¶m : params) {
|
||||
@ -97,7 +105,7 @@ QUrl SubsonicBaseRequest::CreateUrl(const QString &ressource_name, const QList<P
|
||||
|
||||
}
|
||||
|
||||
QNetworkReply *SubsonicBaseRequest::CreateGetRequest(const QString &ressource_name, const QList<Param> ¶ms_provided) {
|
||||
QNetworkReply *SubsonicBaseRequest::CreateGetRequest(const QString &ressource_name, const ParamList ¶ms_provided) const {
|
||||
|
||||
QUrl url = CreateUrl(ressource_name, params_provided);
|
||||
QNetworkRequest req(url);
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "subsonicservice.h"
|
||||
#include "settings/subsonicsettingspage.h"
|
||||
|
||||
class QNetworkAccessManager;
|
||||
class QNetworkReply;
|
||||
@ -51,8 +52,12 @@ class SubsonicBaseRequest : public QObject {
|
||||
typedef QPair<QString, QString> Param;
|
||||
typedef QList<Param> ParamList;
|
||||
|
||||
QUrl CreateUrl(const QString &ressource_name, const QList<Param> ¶ms_provided) const;
|
||||
QNetworkReply *CreateGetRequest(const QString &ressource_name, const QList<Param> ¶ms_provided);
|
||||
public:
|
||||
static void AddPasswordToParams(ParamList ¶ms, const SubsonicSettingsPage::AuthMethod auth_method, const QString &password);
|
||||
|
||||
protected:
|
||||
QUrl CreateUrl(const QString &ressource_name, const ParamList ¶ms_provided) const;
|
||||
QNetworkReply *CreateGetRequest(const QString &ressource_name, const ParamList ¶ms_provided) const;
|
||||
QByteArray GetReplyData(QNetworkReply *reply);
|
||||
QJsonObject ExtractJsonObj(QByteArray &data);
|
||||
|
||||
@ -64,6 +69,7 @@ class SubsonicBaseRequest : public QObject {
|
||||
QUrl server_url() const { return service_->server_url(); }
|
||||
QString username() const { return service_->username(); }
|
||||
QString password() const { return service_->password(); }
|
||||
SubsonicSettingsPage::AuthMethod auth_method() const { return service_->auth_method(); }
|
||||
bool http2() const { return service_->http2(); }
|
||||
bool verify_certificate() const { return service_->verify_certificate(); }
|
||||
bool download_album_covers() const { return service_->download_album_covers(); }
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "core/song.h"
|
||||
|
||||
#include "subsonicservice.h"
|
||||
#include "subsonicbaserequest.h"
|
||||
#include "subsonicurlhandler.h"
|
||||
|
||||
class Application;
|
||||
@ -45,13 +46,14 @@ UrlHandler::LoadResult SubsonicUrlHandler::StartLoading(const QUrl &url) {
|
||||
return LoadResult(url, LoadResult::Error, tr("Missing Subsonic username or password."));
|
||||
}
|
||||
|
||||
ParamList params = ParamList() << Param("c", service_->client_name())
|
||||
<< Param("v", service_->api_version())
|
||||
ParamList params = ParamList() << Param("c", client_name())
|
||||
<< Param("v", api_version())
|
||||
<< Param("f", "json")
|
||||
<< Param("u", service_->username())
|
||||
<< Param("p", QString("enc:" + service_->password().toUtf8().toHex()))
|
||||
<< Param("u", username())
|
||||
<< Param("id", url.path());
|
||||
|
||||
SubsonicBaseRequest::AddPasswordToParams(params, auth_method(), password());
|
||||
|
||||
QUrlQuery url_query;
|
||||
for (const Param ¶m : params) {
|
||||
url_query.addQueryItem(QUrl::toPercentEncoding(param.first), QUrl::toPercentEncoding(param.second));
|
||||
|
@ -42,9 +42,12 @@ class SubsonicUrlHandler : public UrlHandler {
|
||||
explicit SubsonicUrlHandler(Application *app, SubsonicService *service);
|
||||
|
||||
QString scheme() const override { return service_->url_scheme(); }
|
||||
QString client_name() const { return service_->client_name(); }
|
||||
QString api_version() const { return service_->api_version(); }
|
||||
QUrl server_url() const { return service_->server_url(); }
|
||||
QString username() const { return service_->username(); }
|
||||
QString password() const { return service_->password(); }
|
||||
SubsonicSettingsPage::AuthMethod auth_method() const { return service_->auth_method(); }
|
||||
|
||||
LoadResult StartLoading(const QUrl &url) override;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user