mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-26 23:28:14 +03:00
Add a WebFlowCredentialsAccessManager
Fixes #279 Some setups don't make Qt emit the right signals and the client would end up in state where it could not do the initial authentications. This is a similar hack that apparently already was is place for basic http auth. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
73ccccb8a7
commit
9f1f99f4db
1 changed files with 30 additions and 1 deletions
|
@ -24,6 +24,35 @@ namespace OCC {
|
|||
|
||||
Q_LOGGING_CATEGORY(lcWebFlowCredentials, "sync.credentials.webflow", QtInfoMsg)
|
||||
|
||||
class WebFlowCredentialsAccessManager : public AccessManager
|
||||
{
|
||||
public:
|
||||
WebFlowCredentialsAccessManager(const WebFlowCredentials *cred, QObject *parent = nullptr)
|
||||
: AccessManager(parent)
|
||||
, _cred(cred)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
QNetworkReply *createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData) Q_DECL_OVERRIDE
|
||||
{
|
||||
QNetworkRequest req(request);
|
||||
if (!req.attribute(HttpCredentials::DontAddCredentialsAttribute).toBool()) {
|
||||
if (_cred && !_cred->password().isEmpty()) {
|
||||
QByteArray credHash = QByteArray(_cred->user().toUtf8() + ":" + _cred->password().toUtf8()).toBase64();
|
||||
req.setRawHeader("Authorization", "Basic " + credHash);
|
||||
}
|
||||
}
|
||||
|
||||
return AccessManager::createRequest(op, req, outgoingData);
|
||||
}
|
||||
|
||||
private:
|
||||
// The credentials object dies along with the account, while the QNAM might
|
||||
// outlive both.
|
||||
QPointer<const WebFlowCredentials> _cred;
|
||||
};
|
||||
|
||||
WebFlowCredentials::WebFlowCredentials()
|
||||
: _ready(false),
|
||||
_credentialsValid(false)
|
||||
|
@ -56,7 +85,7 @@ QString WebFlowCredentials::password() const {
|
|||
|
||||
QNetworkAccessManager *WebFlowCredentials::createQNAM() const {
|
||||
qCInfo(lcWebFlowCredentials()) << "Get QNAM";
|
||||
AccessManager *qnam = new AccessManager();
|
||||
AccessManager *qnam = new WebFlowCredentialsAccessManager(this);
|
||||
|
||||
connect(qnam, &AccessManager::authenticationRequired, this, &WebFlowCredentials::slotAuthentication);
|
||||
connect(qnam, &AccessManager::finished, this, &WebFlowCredentials::slotFinished);
|
||||
|
|
Loading…
Reference in a new issue