2
* Copyright (C) 2014 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3, as published
6
* by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License along
14
* with this program. If not, see <http://www.gnu.org/licenses/>.
16
* In addition, as a special exception, the copyright holders give
17
* permission to link the code of portions of this program with the
18
* OpenSSL library under certain conditions as described in each
19
* individual source file, and distribute linked combinations
21
* You must obey the GNU General Public License in all respects
22
* for all of the code used other than OpenSSL. If you modify
23
* file(s) with this exception, you may extend this exception to your
24
* version of the file(s), but you are not obligated to do so. If you
25
* do not wish to do so, delete this exception statement from your
26
* version. If you delete this exception statement from all source
27
* files in the program, then also delete it here.
35
#include "ssoservice.h"
38
#include "download-manager.h"
40
namespace ClickScope {
43
DownloadManager::DownloadManager(QObject *parent) :
46
QObject::connect(&service, SIGNAL(credentialsFound(const Token&)),
47
this, SLOT(handleCredentialsFound(Token)));
48
QObject::connect(&service, SIGNAL(credentialsNotFound()),
49
this, SLOT(handleCredentialsNotFound()));
50
QObject::connect(&nam, SIGNAL(finished(QNetworkReply*)),
51
this, SLOT(handleNetworkFinished(QNetworkReply*)));
55
DownloadManager::~DownloadManager(){
58
void DownloadManager::fetchClickToken(QString downloadUrl)
60
service.getCredentials();
61
_downloadUrl = downloadUrl;
64
void DownloadManager::handleCredentialsFound(UbuntuOne::Token token)
66
qDebug() << "Credentials found, signing url " << _downloadUrl;
68
QString authHeader = token.signUrl(_downloadUrl, QStringLiteral("HEAD"));
70
qDebug() << "URL Signed, authHeader is:" << authHeader; // TODO: remove this log
73
req.setRawHeader(QStringLiteral("Authorization").toUtf8(),
75
req.setUrl(_downloadUrl);
79
void DownloadManager::handleCredentialsNotFound()
81
qDebug() << "No credentials were found.";
82
emit clickTokenFetchError(QString("No creds found"));
85
void DownloadManager::handleNetworkFinished(QNetworkReply *reply)
87
// TODO: actually get the header
88
QString clickTokenHeader;
89
QVariant statusAttr = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
90
if(!statusAttr.isValid()) {
91
qDebug() << "Invalid HTTP response.";
95
int status = statusAttr.toInt();
96
qDebug() << "HTTP Status " << status;
99
qDebug() << reply->rawHeaderPairs();
102
qDebug() << reply->readAll();
104
emit clickTokenFetched(clickTokenHeader);
107
} // namespace ClickScope