mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 20:17:01 +02:00
stub a method to ask for domain-server auth from NodeList
This commit is contained in:
parent
582681738a
commit
f4b0375b35
4 changed files with 50 additions and 33 deletions
|
@ -38,15 +38,20 @@ bool AccountManager::hasValidAccessTokenForRootURL(const QUrl &rootURL) {
|
||||||
OAuthAccessToken accessToken = _accessTokens.value(rootURL);
|
OAuthAccessToken accessToken = _accessTokens.value(rootURL);
|
||||||
|
|
||||||
if (accessToken.token.isEmpty() || accessToken.isExpired()) {
|
if (accessToken.token.isEmpty() || accessToken.isExpired()) {
|
||||||
// emit a signal so somebody can call back to us and request an access token given a username and password
|
|
||||||
qDebug() << "An access token is required for requests to" << qPrintable(rootURL.toString());
|
qDebug() << "An access token is required for requests to" << qPrintable(rootURL.toString());
|
||||||
emit authenticationRequiredForRootURL(rootURL);
|
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AccountManager::checkAndSignalForAccessTokenForRootURL(const QUrl& rootURL) {
|
||||||
|
if (!hasValidAccessTokenForRootURL(rootURL)) {
|
||||||
|
// emit a signal so somebody can call back to us and request an access token given a username and password
|
||||||
|
emit authenticationRequiredForRootURL(rootURL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AccountManager::requestAccessToken(const QUrl& rootURL, const QString& username, const QString& password) {
|
void AccountManager::requestAccessToken(const QUrl& rootURL, const QString& username, const QString& password) {
|
||||||
if (_networkAccessManager) {
|
if (_networkAccessManager) {
|
||||||
if (_clientIDs.contains(rootURL)) {
|
if (_clientIDs.contains(rootURL)) {
|
||||||
|
|
|
@ -23,6 +23,7 @@ public:
|
||||||
static AccountManager& getInstance();
|
static AccountManager& getInstance();
|
||||||
|
|
||||||
bool hasValidAccessTokenForRootURL(const QUrl& rootURL);
|
bool hasValidAccessTokenForRootURL(const QUrl& rootURL);
|
||||||
|
bool checkAndSignalForAccessTokenForRootURL(const QUrl& rootURL);
|
||||||
|
|
||||||
void requestAccessToken(const QUrl& rootURL, const QString& username, const QString& password);
|
void requestAccessToken(const QUrl& rootURL, const QString& username, const QString& password);
|
||||||
|
|
||||||
|
|
|
@ -474,40 +474,45 @@ void NodeList::sendDomainServerCheckIn() {
|
||||||
// we don't know our public socket and we need to send it to the domain server
|
// we don't know our public socket and we need to send it to the domain server
|
||||||
// send a STUN request to figure it out
|
// send a STUN request to figure it out
|
||||||
sendSTUNRequest();
|
sendSTUNRequest();
|
||||||
} else if (!_domainInfo.getIP().isNull()
|
} else if (!_domainInfo.getIP().isNull()) {
|
||||||
&& (_domainInfo.getRootAuthenticationURL().isEmpty()
|
if (_domainInfo.getRootAuthenticationURL().isEmpty() || !_sessionUUID.isNull()
|
||||||
|| !_sessionUUID.isNull()
|
|| !_domainInfo.getRegistrationToken().isEmpty()) {
|
||||||
|| !_domainInfo.getRegistrationToken().isEmpty()) ) {
|
// construct the DS check in packet
|
||||||
// construct the DS check in packet
|
|
||||||
|
PacketType domainPacketType = _domainInfo.getRegistrationToken().isEmpty()
|
||||||
PacketType domainPacketType = _domainInfo.getRegistrationToken().isEmpty()
|
|
||||||
? PacketTypeDomainListRequest
|
? PacketTypeDomainListRequest
|
||||||
: PacketTypeDomainConnectRequest;
|
: PacketTypeDomainConnectRequest;
|
||||||
|
|
||||||
QByteArray domainServerPacket = byteArrayWithPopluatedHeader(domainPacketType);
|
QByteArray domainServerPacket = byteArrayWithPopluatedHeader(domainPacketType);
|
||||||
QDataStream packetStream(&domainServerPacket, QIODevice::Append);
|
QDataStream packetStream(&domainServerPacket, QIODevice::Append);
|
||||||
|
|
||||||
// pack our data to send to the domain-server
|
// pack our data to send to the domain-server
|
||||||
packetStream << _ownerType << _publicSockAddr
|
packetStream << _ownerType << _publicSockAddr
|
||||||
<< HifiSockAddr(QHostAddress(getHostOrderLocalAddress()), _nodeSocket.localPort())
|
<< HifiSockAddr(QHostAddress(getHostOrderLocalAddress()), _nodeSocket.localPort())
|
||||||
<< (quint8) _nodeTypesOfInterest.size();
|
<< (quint8) _nodeTypesOfInterest.size();
|
||||||
|
|
||||||
// copy over the bytes for node types of interest, if required
|
// copy over the bytes for node types of interest, if required
|
||||||
foreach (NodeType_t nodeTypeOfInterest, _nodeTypesOfInterest) {
|
foreach (NodeType_t nodeTypeOfInterest, _nodeTypesOfInterest) {
|
||||||
packetStream << nodeTypeOfInterest;
|
packetStream << nodeTypeOfInterest;
|
||||||
|
}
|
||||||
|
|
||||||
|
writeDatagram(domainServerPacket, _domainInfo.getSockAddr(), _domainInfo.getConnectionSecret());
|
||||||
|
const int NUM_DOMAIN_SERVER_CHECKINS_PER_STUN_REQUEST = 5;
|
||||||
|
static unsigned int numDomainCheckins = 0;
|
||||||
|
|
||||||
|
// send a STUN request every Nth domain server check in so we update our public socket, if required
|
||||||
|
if (numDomainCheckins++ % NUM_DOMAIN_SERVER_CHECKINS_PER_STUN_REQUEST == 0) {
|
||||||
|
sendSTUNRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
// increment the count of un-replied check-ins
|
||||||
|
_numNoReplyDomainCheckIns++;
|
||||||
|
} else if (!_domainInfo.getRootAuthenticationURL().isEmpty() && _sessionUUID.isNull()
|
||||||
|
&& AccountManager::getInstance().hasValidAccessTokenForRootURL(_domainInfo.getRootAuthenticationURL())) {
|
||||||
|
// we have an access token we can use for the authentication server the domain-server requested
|
||||||
|
// so ask that server to provide us with information to connect to the domain-server
|
||||||
|
requestAuthForDomainServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
writeDatagram(domainServerPacket, _domainInfo.getSockAddr(), _domainInfo.getConnectionSecret());
|
|
||||||
const int NUM_DOMAIN_SERVER_CHECKINS_PER_STUN_REQUEST = 5;
|
|
||||||
static unsigned int numDomainCheckins = 0;
|
|
||||||
|
|
||||||
// send a STUN request every Nth domain server check in so we update our public socket, if required
|
|
||||||
if (numDomainCheckins++ % NUM_DOMAIN_SERVER_CHECKINS_PER_STUN_REQUEST == 0) {
|
|
||||||
sendSTUNRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
// increment the count of un-replied check-ins
|
|
||||||
_numNoReplyDomainCheckIns++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -566,6 +571,10 @@ int NodeList::processDomainServerList(const QByteArray& packet) {
|
||||||
return readNodes;
|
return readNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NodeList::requestAuthForDomainServer() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void NodeList::processDomainServerAuthRequest(const QByteArray& packet) {
|
void NodeList::processDomainServerAuthRequest(const QByteArray& packet) {
|
||||||
QDataStream authPacketStream(packet);
|
QDataStream authPacketStream(packet);
|
||||||
authPacketStream.skipRawData(numBytesForPacketHeader(packet));
|
authPacketStream.skipRawData(numBytesForPacketHeader(packet));
|
||||||
|
@ -576,8 +585,9 @@ void NodeList::processDomainServerAuthRequest(const QByteArray& packet) {
|
||||||
|
|
||||||
_domainInfo.setRootAuthenticationURL(authenticationRootURL);
|
_domainInfo.setRootAuthenticationURL(authenticationRootURL);
|
||||||
|
|
||||||
if (AccountManager::getInstance().hasValidAccessTokenForRootURL(authenticationRootURL)) {
|
if (AccountManager::getInstance().checkAndSignalForAccessTokenForRootURL(authenticationRootURL)) {
|
||||||
// request a domain-server registration
|
// request a domain-server auth
|
||||||
|
requestAuthForDomainServer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -148,6 +148,7 @@ private:
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
void processDomainServerAuthRequest(const QByteArray& packet);
|
void processDomainServerAuthRequest(const QByteArray& packet);
|
||||||
|
void requestAuthForDomainServer();
|
||||||
|
|
||||||
NodeHash _nodeHash;
|
NodeHash _nodeHash;
|
||||||
QMutex _nodeHashMutex;
|
QMutex _nodeHashMutex;
|
||||||
|
|
Loading…
Reference in a new issue