Add support for metaverse API's with paths.

This commit is contained in:
Kalila L 2020-09-15 20:07:00 -04:00
parent d5f5c76878
commit e3a6dc18af
10 changed files with 68 additions and 53 deletions

View file

@ -8,20 +8,20 @@
{
"name": "access_token",
"label": "Access Token",
"help": "This is your OAuth access token to connect this domain-server with your High Fidelity account. <br/>It can be generated by clicking the 'Connect Account' button above.<br/>You can also go to the <a href='https://metaverse.highfidelity.com/user/security' target='_blank'>My Security</a> page of your account and generate a token with the 'domains' scope and paste it here.",
"help": "This is your OAuth access token to connect this domain-server with your Metaverse account. <br/>It can be generated by clicking the 'Connect Account' button above.<br/>You can also go to the Security page of your account on your Metaverse Server and generate a token with the 'domains' scope and paste it here.",
"advanced": true,
"backup": false
},
{
"name": "id",
"label": "Domain ID",
"help": "This is your High Fidelity domain ID. If you do not want your domain to be registered in the High Fidelity metaverse you can leave this blank.",
"help": "This is your Metaverse domain ID. If you do not want your domain to be registered in the Metaverse you can leave this blank.",
"advanced": true
},
{
"name": "automatic_networking",
"label": "Automatic Networking",
"help": "This defines how other nodes in the High Fidelity metaverse will be able to reach your domain-server.<br/>If you don't want to deal with any network settings, use full automatic networking.",
"help": "This defines how other nodes in the Metaverse will be able to reach your domain-server.<br/>If you don't want to deal with any network settings, use full automatic networking.",
"default": "disabled",
"type": "select",
"options": [
@ -35,7 +35,7 @@
},
{
"value": "disabled",
"label": "None: use the network information I have entered for this domain at metaverse.highfidelity.com"
"label": "None: use the network information I have entered for this domain at in the Metaverse Server."
}
]
},
@ -50,7 +50,7 @@
{
"name": "enable_packet_verification",
"label": "Enable Packet Verification",
"help": "Enable secure checksums on communication that uses the High Fidelity protocol. Increases security with possibly a small performance penalty.",
"help": "Enable secure checksums on communication that uses the Metaverse protocol. Increases security with possibly a small performance penalty.",
"default": true,
"type": "checkbox",
"advanced": true
@ -160,7 +160,7 @@
"name": "descriptors",
"label": "Description",
"restart": false,
"help": "This data will be queryable from your server. It may be collected by High Fidelity and used to share your domain with others.",
"help": "This data will be queryable from your server. It may be collected by the Metaverse and used to share your domain with others.",
"settings": [
{
"name": "world_name",

View file

@ -52,7 +52,7 @@ var URLs = {
// STABLE METAVERSE_URL: https://metaverse.highfidelity.com
// STAGING METAVERSE_URL: https://staging.highfidelity.com
DEFAULT_METAVERSE_URL: "https://metaverse.vircadia.com/live",
CDN_URL: 'https://cdn.highfidelity.com',
CDN_URL: 'https://content.vircadia.com/eu-c-1',
PLACE_URL: 'https://hifi.place',
};
@ -501,9 +501,9 @@ function prepareAccessTokenPrompt(callback) {
}
function getMetaverseUrl(callback) {
$.ajax('/domain/metaverse_info', {
$.ajax('/api/metaverse_info', {
success: function(data) {
callback(data.metaverse.metaverse_url);
callback(data.metaverse_url);
},
error: function() {
callback(URLs.DEFAULT_METAVERSE_URL);

View file

@ -1156,7 +1156,7 @@ QUrl DomainServer::oauthAuthorizationURL(const QUuid& stateUUID) {
QUrl authorizationURL = _oauthProviderURL;
const QString OAUTH_AUTHORIZATION_PATH = "/oauth/authorize";
authorizationURL.setPath(OAUTH_AUTHORIZATION_PATH);
authorizationURL.setPath(MetaverseAPI::getCurrentMetaverseServerURLPath() + OAUTH_AUTHORIZATION_PATH);
QUrlQuery authorizationQuery;
@ -1620,7 +1620,7 @@ void DomainServer::sendICEServerAddressToMetaverseAPI() {
callbackParameters.errorCallbackMethod = "handleFailedICEServerAddressUpdate";
callbackParameters.jsonCallbackMethod = "handleSuccessfulICEServerAddressUpdate";
qCDebug(domain_server_ice) << "Updating ice-server address in High Fidelity Metaverse API to"
qCDebug(domain_server_ice) << "Updating ice-server address in Metaverse API to"
<< (_iceServerSocket.isNull() ? "" : _iceServerSocket.getAddress().toString());
static const QString DOMAIN_ICE_ADDRESS_UPDATE = "/api/v1/domains/%1/ice_server_address";
@ -1979,7 +1979,6 @@ const QString URI_OAUTH = "/oauth";
bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url, bool skipSubHandler) {
const QString JSON_MIME_TYPE = "application/json";
const QString URI_DOMAIN_METAVERSE_INFO = "/domain/metaverse_info";
const QString URI_ID = "/id";
const QString URI_ASSIGNMENT = "/assignment";
const QString URI_NODES = "/nodes";
@ -2064,20 +2063,6 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
connection->respond(HTTPConnection::StatusCode200, uuidStringWithoutCurlyBraces(domainID).toLocal8Bit());
return true;
}
// check if this is a request for our selected metaverse server info
if (connection->requestOperation() == QNetworkAccessManager::GetOperation
&& url.path() == URI_DOMAIN_METAVERSE_INFO) {
const QString MIME_TYPE = "application/json";
QString metaverseURL{ MetaverseAPI::getCurrentMetaverseServerURL().toString() };
QJsonObject jsonObject{ { "metaverse_url", metaverseURL } };
QString domainMetaverseInfoJSON =
QString("{\"metaverse\":%1}").arg(QString(QJsonDocument(jsonObject).toJson(QJsonDocument::Compact)));
connection->respond(HTTPConnection::StatusCode200, domainMetaverseInfoJSON.toUtf8(), qPrintable(MIME_TYPE));
return true;
}
// all requests below require a cookie to prove authentication so check that first
bool isAuthenticated { false };
@ -2577,7 +2562,7 @@ bool DomainServer::handleHTTPSRequest(HTTPSConnection* connection, const QUrl &u
const QString OAUTH_TOKEN_REQUEST_PATH = "/oauth/token";
QUrl tokenRequestUrl = _oauthProviderURL;
tokenRequestUrl.setPath(OAUTH_TOKEN_REQUEST_PATH);
tokenRequestUrl.setPath(MetaverseAPI::getCurrentMetaverseServerURLPath() + OAUTH_TOKEN_REQUEST_PATH);
const QString OAUTH_GRANT_TYPE_POST_STRING = "grant_type=authorization_code";
QString tokenPostBody = OAUTH_GRANT_TYPE_POST_STRING;
@ -2891,7 +2876,7 @@ QNetworkReply* DomainServer::profileRequestGivenTokenReply(QNetworkReply* tokenR
// fire off a request to get this user's identity so we can see if we will let them in
QUrl profileURL = _oauthProviderURL;
profileURL.setPath("/api/v1/user/profile");
profileURL.setPath(MetaverseAPI::getCurrentMetaverseServerURLPath() + "/api/v1/user/profile");
profileURL.setQuery(QString("%1=%2").arg(OAUTH_JSON_ACCESS_TOKEN_KEY, accessToken));
qDebug() << "Sending profile request to: " << profileURL;

View file

@ -211,8 +211,15 @@ void IceServer::requestDomainPublicKey(const QUuid& domainID) {
auto& networkAccessManager = NetworkAccessManager::getInstance();
QUrl publicKeyURL{ MetaverseAPI::getCurrentMetaverseServerURL() };
// qDebug() << "publicKeyURL" << publicKeyURL;
// qDebug() << "MetaverseAPI::getCurrentMetaverseServerURLPath()" << MetaverseAPI::getCurrentMetaverseServerURLPath();
QString publicKeyPath = QString("/api/v1/domains/%1/public_key").arg(uuidStringWithoutCurlyBraces(domainID));
publicKeyURL.setPath(publicKeyPath);
publicKeyURL.setPath("/" + MetaverseAPI::getCurrentMetaverseServerURLPath() + publicKeyPath);
// qDebug() << "publicKeyPath" << publicKeyPath;
// qDebug() << "publicKeyURL.setPath" << "/" + MetaverseAPI::getCurrentMetaverseServerURLPath() + publicKeyPath;
// qDebug() << "publicKeyURL" << publicKeyURL;
// qDebug() << "publicKeyURL.isValid()" << publicKeyURL.isValid();
// qDebug() << "publicKeyURL.errorString()" << publicKeyURL.errorString();
QNetworkRequest publicKeyRequest { publicKeyURL };
publicKeyRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);

View file

@ -30,7 +30,7 @@ QNetworkRequest createNetworkRequest() {
QNetworkRequest request;
QUrl requestURL = MetaverseAPI::getCurrentMetaverseServerURL();
requestURL.setPath(USER_ACTIVITY_URL);
requestURL.setPath(MetaverseAPI::getCurrentMetaverseServerURLPath() + USER_ACTIVITY_URL);
request.setUrl(requestURL);

View file

@ -1492,7 +1492,7 @@ void EntityTree::startDynamicDomainVerificationOnServer(float minimumAgeToRemove
networkRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
QUrl requestURL = MetaverseAPI::getCurrentMetaverseServerURL();
requestURL.setPath("/api/v1/commerce/proof_of_purchase_status/location");
requestURL.setPath(MetaverseAPI::getCurrentMetaverseServerURLPath() + "/api/v1/commerce/proof_of_purchase_status/location");
QJsonObject request;
request["certificate_id"] = certificateID;
networkRequest.setUrl(requestURL);
@ -1724,7 +1724,7 @@ void EntityTree::validatePop(const QString& certID, const EntityItemID& entityIt
networkRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
QUrl requestURL = MetaverseAPI::getCurrentMetaverseServerURL();
requestURL.setPath("/api/v1/commerce/proof_of_purchase_status/transfer");
requestURL.setPath(MetaverseAPI::getCurrentMetaverseServerURLPath() + "/api/v1/commerce/proof_of_purchase_status/transfer");
QJsonObject request;
request["certificate_id"] = certID;
networkRequest.setUrl(requestURL);

View file

@ -221,17 +221,22 @@ QNetworkRequest AccountManager::createRequest(QString path, AccountManagerAuth::
uuidStringWithoutCurlyBraces(_sessionID).toLocal8Bit());
QUrl requestURL = _authURL;
if (requestURL.isEmpty()) { // Assignment client doesn't set _authURL.
requestURL = getMetaverseServerURL();
}
// qCDebug(networking) << "Received path" << path;
// qCDebug(networking) << "path.left(path.indexOf(\" ? \"))" << path.left(path.indexOf("?"));
// qCDebug(networking) << "getMetaverseServerURLPath(true)" << getMetaverseServerURLPath(true);
int queryStringLocation = path.indexOf("?");
if (path.startsWith("/")) {
requestURL.setPath(path.left(queryStringLocation));
requestURL.setPath(getMetaverseServerURLPath(false) + path.left(queryStringLocation));
} else {
requestURL.setPath("/" + path.left(queryStringLocation));
requestURL.setPath(getMetaverseServerURLPath(true) + path.left(queryStringLocation));
}
// qCDebug(networking) << "Creating request path" << requestURL;
if (queryStringLocation >= 0) {
QUrlQuery query(path.mid(queryStringLocation+1));
@ -556,7 +561,7 @@ void AccountManager::requestAccessToken(const QString& login, const QString& pas
request.setHeader(QNetworkRequest::UserAgentHeader, _userAgentGetter());
QUrl grantURL = _authURL;
grantURL.setPath("/oauth/token");
grantURL.setPath(getMetaverseServerURLPath() + "/oauth/token");
QByteArray postData;
postData.append("grant_type=password&");
@ -579,7 +584,7 @@ void AccountManager::requestAccessTokenWithAuthCode(const QString& authCode, con
request.setHeader(QNetworkRequest::UserAgentHeader, _userAgentGetter());
QUrl grantURL = _authURL;
grantURL.setPath("/oauth/token");
grantURL.setPath(getMetaverseServerURLPath() + "/oauth/token");
QByteArray postData;
postData.append("grant_type=authorization_code&");
@ -602,7 +607,7 @@ void AccountManager::requestAccessTokenWithSteam(QByteArray authSessionTicket) {
request.setHeader(QNetworkRequest::UserAgentHeader, _userAgentGetter());
QUrl grantURL = _authURL;
grantURL.setPath("/oauth/token");
grantURL.setPath(getMetaverseServerURLPath() + "/oauth/token");
QByteArray postData;
postData.append("grant_type=password&");
@ -624,7 +629,7 @@ void AccountManager::requestAccessTokenWithOculus(const QString& nonce, const QS
request.setHeader(QNetworkRequest::UserAgentHeader, _userAgentGetter());
QUrl grantURL = _authURL;
grantURL.setPath("/oauth/token");
grantURL.setPath(getMetaverseServerURLPath() + "/oauth/token");
QByteArray postData;
postData.append("grant_type=password&");
@ -655,7 +660,7 @@ void AccountManager::refreshAccessToken() {
request.setHeader(QNetworkRequest::UserAgentHeader, _userAgentGetter());
QUrl grantURL = _authURL;
grantURL.setPath("/oauth/token");
grantURL.setPath(getMetaverseServerURLPath() + "/oauth/token");
QByteArray postData;
postData.append("grant_type=refresh_token&");
@ -688,7 +693,7 @@ void AccountManager::setAccessTokens(const QString& response) {
} else {
// clear the path from the response URL so we have the right root URL for this access token
QUrl rootURL = rootObject.contains("url") ? rootObject["url"].toString() : _authURL;
rootURL.setPath("");
rootURL.setPath(getMetaverseServerURLPath() + "");
qCDebug(networking) << "Storing an account with access-token for" << qPrintable(rootURL.toString());
@ -723,7 +728,7 @@ void AccountManager::requestAccessTokenFinished() {
} else {
// clear the path from the response URL so we have the right root URL for this access token
QUrl rootURL = requestReply->url();
rootURL.setPath("");
rootURL.setPath(getMetaverseServerURLPath() + "");
qCDebug(networking) << "Storing an account with access-token for" << qPrintable(rootURL.toString());
@ -759,7 +764,7 @@ void AccountManager::refreshAccessTokenFinished() {
} else {
// clear the path from the response URL so we have the right root URL for this access token
QUrl rootURL = requestReply->url();
rootURL.setPath("");
rootURL.setPath(getMetaverseServerURLPath() + "");
qCDebug(networking) << "Storing an account with a refreshed access-token for" << qPrintable(rootURL.toString());
@ -784,7 +789,7 @@ void AccountManager::requestProfile() {
QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
QUrl profileURL = _authURL;
profileURL.setPath("/api/v1/user/profile");
profileURL.setPath(getMetaverseServerURLPath() + "/api/v1/user/profile");
QNetworkRequest profileRequest(profileURL);
profileRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
@ -834,7 +839,7 @@ void AccountManager::requestAccountSettings() {
QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
QUrl lockerURL = _authURL;
lockerURL.setPath("/api/v1/user/locker");
lockerURL.setPath(getMetaverseServerURLPath() + "/api/v1/user/locker");
QNetworkRequest lockerRequest(lockerURL);
lockerRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
@ -905,7 +910,7 @@ void AccountManager::postAccountSettings() {
QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
QUrl lockerURL = _authURL;
lockerURL.setPath("/api/v1/user/locker");
lockerURL.setPath(getMetaverseServerURLPath() + "/api/v1/user/locker");
QNetworkRequest lockerRequest(lockerURL);
lockerRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);

View file

@ -101,6 +101,9 @@ public:
const QString& getTemporaryDomainKey(const QUuid& domainID) { return _accountInfo.getTemporaryDomainKey(domainID); }
QUrl getMetaverseServerURL() { return MetaverseAPI::getCurrentMetaverseServerURL(); }
QString getMetaverseServerURLPath(bool appendForwardSlash = false) {
return MetaverseAPI::getCurrentMetaverseServerURLPath(appendForwardSlash);
}
void removeAccountFromFile();

View file

@ -2,8 +2,8 @@
// MetaverseAPI.cpp
// libraries/networking/src
//
// Created by Kalila (kasenvr) on 2019-12-16.
// Copyright 2019 Vircadia
// Created by Kalila L. on 2019-12-16.
// Copyright 2019 Vircadia contributors.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
@ -23,7 +23,7 @@ namespace MetaverseAPI {
QUrl getCurrentMetaverseServerURL() {
QUrl selectedMetaverseURL;
Setting::Handle<QUrl> selectedMetaverseURLSetting("private/selectedMetaverseURL",
NetworkingConstants::METAVERSE_SERVER_URL_STABLE);
NetworkingConstants::METAVERSE_SERVER_URL_STABLE);
selectedMetaverseURL = selectedMetaverseURLSetting.get();
@ -32,7 +32,21 @@ namespace MetaverseAPI {
if (QProcessEnvironment::systemEnvironment().contains(HIFI_METAVERSE_URL_ENV)) {
return QUrl(QProcessEnvironment::systemEnvironment().value(HIFI_METAVERSE_URL_ENV));
}
return selectedMetaverseURL;
};
}
QString getCurrentMetaverseServerURLPath(bool appendForwardSlash){
QString path = getCurrentMetaverseServerURL().path();
if (path.isEmpty()) {
return path;
}
if (appendForwardSlash) {
path.append("/");
}
return path;
};
} // namespace MetaverseAPI

View file

@ -2,8 +2,8 @@
// MetaverseAPI.h
// libraries/networking/src
//
// Created by Kalila (kasenvr) on 2019-12-16.
// Copyright 2019 Vircadia
// Created by Kalila L. on 2019-12-16.
// Copyright 2019 Vircadia contributors.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
@ -17,6 +17,7 @@
namespace MetaverseAPI {
QUrl getCurrentMetaverseServerURL();
QString getCurrentMetaverseServerURLPath(bool appendForwardSlash = false);
}
#endif // athena_MetaverseAPI_h