mirror of
https://github.com/overte-org/overte.git
synced 2025-04-16 13:56:24 +02:00
present a login window on app start
This commit is contained in:
parent
e637e48598
commit
b09ed1dff1
6 changed files with 31 additions and 26 deletions
|
@ -185,7 +185,7 @@ void AssignmentClient::handleAuthenticationRequest() {
|
|||
// ask the account manager to log us in from the env variables
|
||||
accountManager.requestAccessToken(username, password);
|
||||
} else {
|
||||
qDebug() << "Authentication was requested against" << qPrintable(accountManager.getRootURL().toString())
|
||||
qDebug() << "Authentication was requested against" << qPrintable(accountManager.getAuthURL().toString())
|
||||
<< "but both or one of" << qPrintable(DATA_SERVER_USERNAME_ENV)
|
||||
<< "/" << qPrintable(DATA_SERVER_PASSWORD_ENV) << "are not set. Unable to authenticate.";
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ DomainServer::DomainServer(int argc, char* argv[]) :
|
|||
QString password = sysEnvironment.value(DATA_SERVER_PASSWORD_ENV);
|
||||
|
||||
AccountManager& accountManager = AccountManager::getInstance();
|
||||
accountManager.setRootURL(_nodeAuthenticationURL);
|
||||
accountManager.setAuthURL(_nodeAuthenticationURL);
|
||||
|
||||
if (!username.isEmpty() && !password.isEmpty()) {
|
||||
|
||||
|
|
|
@ -232,6 +232,12 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
|
|||
AccountManager& accountManager = AccountManager::getInstance();
|
||||
connect(&accountManager, &AccountManager::authRequired, Menu::getInstance(), &Menu::loginForCurrentDomain);
|
||||
connect(&accountManager, &AccountManager::usernameChanged, this, &Application::updateWindowTitle);
|
||||
|
||||
// set the account manager's root URL and trigger a login request if we don't have the access token
|
||||
accountManager.setAuthURL(DEFAULT_NODE_AUTH_URL);
|
||||
|
||||
// once the event loop has started, check and signal for an access token
|
||||
QMetaObject::invokeMethod(&accountManager, "checkAndSignalForAccessToken", Qt::QueuedConnection);
|
||||
|
||||
_settings = new QSettings(this);
|
||||
|
||||
|
@ -311,7 +317,6 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
|
|||
|
||||
_overlays.init(_glWidget); // do this before scripts load
|
||||
|
||||
|
||||
// do this as late as possible so that all required subsystems are inialized
|
||||
loadScripts();
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ Q_DECLARE_METATYPE(JSONCallbackParameters)
|
|||
const QString ACCOUNTS_GROUP = "accounts";
|
||||
|
||||
AccountManager::AccountManager() :
|
||||
_rootURL(),
|
||||
_authURL(),
|
||||
_networkAccessManager(),
|
||||
_pendingCallbackMap(),
|
||||
_accounts()
|
||||
|
@ -67,15 +67,15 @@ const QString DOUBLE_SLASH_SUBSTITUTE = "slashslash";
|
|||
|
||||
void AccountManager::logout() {
|
||||
// a logout means we want to delete the DataServerAccountInfo we currently have for this URL, in-memory and in file
|
||||
_accounts.remove(_rootURL);
|
||||
_accounts.remove(_authURL);
|
||||
|
||||
QSettings settings;
|
||||
settings.beginGroup(ACCOUNTS_GROUP);
|
||||
|
||||
QString keyURLString(_rootURL.toString().replace("//", DOUBLE_SLASH_SUBSTITUTE));
|
||||
QString keyURLString(_authURL.toString().replace("//", DOUBLE_SLASH_SUBSTITUTE));
|
||||
settings.remove(keyURLString);
|
||||
|
||||
qDebug() << "Removed account info for" << _rootURL << "from in-memory accounts and .ini file";
|
||||
qDebug() << "Removed account info for" << _authURL << "from in-memory accounts and .ini file";
|
||||
|
||||
emit logoutComplete();
|
||||
// the username has changed to blank
|
||||
|
@ -83,11 +83,11 @@ void AccountManager::logout() {
|
|||
|
||||
}
|
||||
|
||||
void AccountManager::setRootURL(const QUrl& rootURL) {
|
||||
if (_rootURL != rootURL) {
|
||||
_rootURL = rootURL;
|
||||
void AccountManager::setAuthURL(const QUrl& authURL) {
|
||||
if (_authURL != authURL) {
|
||||
_authURL = authURL;
|
||||
|
||||
qDebug() << "URL for node authentication has been changed to" << qPrintable(_rootURL.toString());
|
||||
qDebug() << "URL for node authentication has been changed to" << qPrintable(_authURL.toString());
|
||||
qDebug() << "Re-setting authentication flow.";
|
||||
|
||||
// tell listeners that the auth endpoint has changed
|
||||
|
@ -109,9 +109,9 @@ void AccountManager::invokedRequest(const QString& path, QNetworkAccessManager::
|
|||
if (hasValidAccessToken()) {
|
||||
QNetworkRequest authenticatedRequest;
|
||||
|
||||
QUrl requestURL = _rootURL;
|
||||
QUrl requestURL = _authURL;
|
||||
requestURL.setPath(path);
|
||||
requestURL.setQuery("access_token=" + _accounts.value(_rootURL).getAccessToken().token);
|
||||
requestURL.setQuery("access_token=" + _accounts.value(_authURL).getAccessToken().token);
|
||||
|
||||
authenticatedRequest.setUrl(requestURL);
|
||||
|
||||
|
@ -202,11 +202,11 @@ void AccountManager::passErrorToCallback(QNetworkReply::NetworkError errorCode)
|
|||
}
|
||||
|
||||
bool AccountManager::hasValidAccessToken() {
|
||||
DataServerAccountInfo accountInfo = _accounts.value(_rootURL);
|
||||
DataServerAccountInfo accountInfo = _accounts.value(_authURL);
|
||||
|
||||
if (accountInfo.getAccessToken().token.isEmpty() || accountInfo.getAccessToken().isExpired()) {
|
||||
if (VERBOSE_HTTP_REQUEST_DEBUGGING) {
|
||||
qDebug() << "An access token is required for requests to" << qPrintable(_rootURL.toString());
|
||||
qDebug() << "An access token is required for requests to" << qPrintable(_authURL.toString());
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -229,7 +229,7 @@ bool AccountManager::checkAndSignalForAccessToken() {
|
|||
void AccountManager::requestAccessToken(const QString& login, const QString& password) {
|
||||
QNetworkRequest request;
|
||||
|
||||
QUrl grantURL = _rootURL;
|
||||
QUrl grantURL = _authURL;
|
||||
grantURL.setPath("/oauth/token");
|
||||
|
||||
QByteArray postData;
|
||||
|
|
|
@ -41,17 +41,17 @@ public:
|
|||
const JSONCallbackParameters& callbackParams = JSONCallbackParameters(),
|
||||
const QByteArray& dataByteArray = QByteArray());
|
||||
|
||||
const QUrl& getRootURL() const { return _rootURL; }
|
||||
void setRootURL(const QUrl& rootURL);
|
||||
bool hasAuthEndpoint() { return !_rootURL.isEmpty(); }
|
||||
const QUrl& getAuthURL() const { return _authURL; }
|
||||
void setAuthURL(const QUrl& authURL);
|
||||
bool hasAuthEndpoint() { return !_authURL.isEmpty(); }
|
||||
|
||||
bool isLoggedIn() { return !_rootURL.isEmpty() && hasValidAccessToken(); }
|
||||
bool isLoggedIn() { return !_authURL.isEmpty() && hasValidAccessToken(); }
|
||||
bool hasValidAccessToken();
|
||||
bool checkAndSignalForAccessToken();
|
||||
Q_INVOKABLE bool checkAndSignalForAccessToken();
|
||||
|
||||
void requestAccessToken(const QString& login, const QString& password);
|
||||
|
||||
QString getUsername() const { return _accounts[_rootURL].getUsername(); }
|
||||
QString getUsername() const { return _accounts[_authURL].getUsername(); }
|
||||
|
||||
public slots:
|
||||
void requestFinished();
|
||||
|
@ -61,7 +61,7 @@ signals:
|
|||
void authRequired();
|
||||
void authEndpointChanged();
|
||||
void usernameChanged(const QString& username);
|
||||
void loginComplete(const QUrl& rootURL);
|
||||
void loginComplete(const QUrl& authURL);
|
||||
void logoutComplete();
|
||||
private slots:
|
||||
void passSuccessToCallback();
|
||||
|
@ -74,7 +74,7 @@ private:
|
|||
Q_INVOKABLE void invokedRequest(const QString& path, QNetworkAccessManager::Operation operation,
|
||||
const JSONCallbackParameters& callbackParams, const QByteArray& dataByteArray);
|
||||
|
||||
QUrl _rootURL;
|
||||
QUrl _authURL;
|
||||
QNetworkAccessManager _networkAccessManager;
|
||||
QMap<QNetworkReply*, JSONCallbackParameters> _pendingCallbackMap;
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ bool NodeList::packetVersionAndHashMatch(const QByteArray& packet) {
|
|||
|
||||
// we also know this domain-server requires no authentication
|
||||
// so set the account manager root URL empty
|
||||
AccountManager::getInstance().setRootURL(QUrl());
|
||||
AccountManager::getInstance().setAuthURL(QUrl());
|
||||
}
|
||||
|
||||
if (_domainInfo.getUUID() == uuidFromPacketHeader(packet)) {
|
||||
|
@ -644,7 +644,7 @@ void NodeList::processDomainServerAuthRequest(const QByteArray& packet) {
|
|||
QUrl authenticationRootURL;
|
||||
authPacketStream >> authenticationRootURL;
|
||||
|
||||
accountManager.setRootURL(authenticationRootURL);
|
||||
accountManager.setAuthURL(authenticationRootURL);
|
||||
_domainInfo.setRootAuthenticationURL(authenticationRootURL);
|
||||
|
||||
if (AccountManager::getInstance().checkAndSignalForAccessToken()) {
|
||||
|
|
Loading…
Reference in a new issue