mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 12:04:18 +02:00
add a DataWebDialog for authenticated access to data-web html
This commit is contained in:
parent
9ee063bdc1
commit
e2c3b626b3
8 changed files with 138 additions and 3 deletions
|
@ -68,6 +68,7 @@
|
|||
#include <UUID.h>
|
||||
|
||||
#include "Application.h"
|
||||
#include "ui/DataWebDialog.h"
|
||||
#include "InterfaceVersion.h"
|
||||
#include "Menu.h"
|
||||
#include "ModelUploader.h"
|
||||
|
@ -429,6 +430,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
|||
MIDIManager& midiManagerInstance = MIDIManager::getInstance();
|
||||
midiManagerInstance.openDefaultPort();
|
||||
#endif
|
||||
|
||||
DataWebDialog* dialogForPath = DataWebDialog::dialogForPath("/locations");
|
||||
dialogForPath->show();
|
||||
}
|
||||
|
||||
Application::~Application() {
|
||||
|
|
39
interface/src/ui/DataWebDialog.cpp
Normal file
39
interface/src/ui/DataWebDialog.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
//
|
||||
// DataWebDialog.cpp
|
||||
// interface/src/ui
|
||||
//
|
||||
// Created by Stephen Birarda on 2014-09-17.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include <qwebview.h>
|
||||
|
||||
#include <AccountManager.h>
|
||||
#include <LimitedNodeList.h>
|
||||
#include <OAuthNetworkAccessManager.h>
|
||||
|
||||
#include "DataWebDialog.h"
|
||||
|
||||
DataWebDialog::DataWebDialog() {
|
||||
// make sure the dialog deletes itself when it closes
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
// use an OAuthNetworkAccessManager instead of regular QNetworkAccessManager so our requests are authed
|
||||
page()->setNetworkAccessManager(OAuthNetworkAccessManager::getInstance());
|
||||
}
|
||||
|
||||
DataWebDialog* DataWebDialog::dialogForPath(const QString& path) {
|
||||
DataWebDialog* dialogWebView = new DataWebDialog();
|
||||
|
||||
QUrl dataWebUrl(DEFAULT_NODE_AUTH_URL);
|
||||
dataWebUrl.setPath(path);
|
||||
|
||||
qDebug() << "Opening a data web dialog for" << dataWebUrl.toString();
|
||||
|
||||
dialogWebView->load(dataWebUrl);
|
||||
|
||||
return dialogWebView;
|
||||
}
|
25
interface/src/ui/DataWebDialog.h
Normal file
25
interface/src/ui/DataWebDialog.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
//
|
||||
// DataWebDialog.h
|
||||
// interface/src/ui
|
||||
//
|
||||
// Created by Stephen Birarda on 2014-09-17.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_DataWebDialog_h
|
||||
#define hifi_DataWebDialog_h
|
||||
|
||||
#include <qobject.h>
|
||||
#include <qwebview.h>
|
||||
|
||||
class DataWebDialog : public QWebView {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DataWebDialog();
|
||||
static DataWebDialog* dialogForPath(const QString& path);
|
||||
};
|
||||
|
||||
#endif // hifi_WebkitDialog_h
|
|
@ -25,8 +25,6 @@
|
|||
|
||||
const bool VERBOSE_HTTP_REQUEST_DEBUGGING = false;
|
||||
|
||||
const QByteArray ACCESS_TOKEN_AUTHORIZATION_HEADER = "Authorization";
|
||||
|
||||
AccountManager& AccountManager::getInstance() {
|
||||
static AccountManager sharedInstance;
|
||||
return sharedInstance;
|
||||
|
|
|
@ -37,6 +37,8 @@ public:
|
|||
QString updateSlot;
|
||||
};
|
||||
|
||||
const QByteArray ACCESS_TOKEN_AUTHORIZATION_HEADER = "Authorization";
|
||||
|
||||
class AccountManager : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
|
|
@ -33,7 +33,7 @@ const char SOLO_NODE_TYPES[2] = {
|
|||
NodeType::AudioMixer
|
||||
};
|
||||
|
||||
const QUrl DEFAULT_NODE_AUTH_URL = QUrl("https://data.highfidelity.io");
|
||||
const QUrl DEFAULT_NODE_AUTH_URL = QUrl("http://localhost:3000");
|
||||
|
||||
LimitedNodeList* LimitedNodeList::_sharedInstance = NULL;
|
||||
|
||||
|
|
43
libraries/networking/src/OAuthNetworkAccessManager.cpp
Normal file
43
libraries/networking/src/OAuthNetworkAccessManager.cpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
//
|
||||
// OAuthNetworkAccessManager.cpp
|
||||
// libraries/networking/src
|
||||
//
|
||||
// Created by Stephen Birarda on 2014-09-18.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QThreadStorage>
|
||||
|
||||
#include "AccountManager.h"
|
||||
|
||||
#include "OAuthNetworkAccessManager.h"
|
||||
|
||||
QThreadStorage<OAuthNetworkAccessManager*> oauthNetworkAccessManagers;
|
||||
|
||||
OAuthNetworkAccessManager* OAuthNetworkAccessManager::getInstance() {
|
||||
if (!oauthNetworkAccessManagers.hasLocalData()) {
|
||||
oauthNetworkAccessManagers.setLocalData(new OAuthNetworkAccessManager());
|
||||
}
|
||||
|
||||
return oauthNetworkAccessManagers.localData();
|
||||
}
|
||||
|
||||
QNetworkReply* OAuthNetworkAccessManager::createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest& req,
|
||||
QIODevice* outgoingData) {
|
||||
AccountManager& accountManager = AccountManager::getInstance();
|
||||
|
||||
if (accountManager.hasValidAccessToken()) {
|
||||
QNetworkRequest authenticatedRequest(req);
|
||||
authenticatedRequest.setRawHeader(ACCESS_TOKEN_AUTHORIZATION_HEADER,
|
||||
accountManager.getAccountInfo().getAccessToken().authorizationHeaderValue());
|
||||
|
||||
return QNetworkAccessManager::createRequest(op, authenticatedRequest, outgoingData);
|
||||
} else {
|
||||
return QNetworkAccessManager::createRequest(op, req, outgoingData);
|
||||
}
|
||||
}
|
24
libraries/networking/src/OAuthNetworkAccessManager.h
Normal file
24
libraries/networking/src/OAuthNetworkAccessManager.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
//
|
||||
// OAuthNetworkAccessManager.h
|
||||
// libraries/networking/src
|
||||
//
|
||||
// Created by Stephen Birarda on 2014-09-18.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_OAuthNetworkAccessManager_h
|
||||
#define hifi_OAuthNetworkAccessManager_h
|
||||
|
||||
#include <QNetworkAccessManager>
|
||||
|
||||
class OAuthNetworkAccessManager : public QNetworkAccessManager {
|
||||
public:
|
||||
static OAuthNetworkAccessManager* getInstance();
|
||||
protected:
|
||||
virtual QNetworkReply* createRequest(Operation op, const QNetworkRequest& req, QIODevice* outgoingData = 0);
|
||||
};
|
||||
|
||||
#endif // hifi_OAuthNetworkAccessManager_h
|
Loading…
Reference in a new issue