mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 19:03:07 +02:00
currently support system wide auth only via hifi data-web
This commit is contained in:
parent
d0269761b6
commit
6d847f29fb
3 changed files with 26 additions and 27 deletions
|
@ -37,7 +37,7 @@ AccountManager::AccountManager() :
|
||||||
_authURL(),
|
_authURL(),
|
||||||
_networkAccessManager(),
|
_networkAccessManager(),
|
||||||
_pendingCallbackMap(),
|
_pendingCallbackMap(),
|
||||||
_accounts()
|
_accountInfo()
|
||||||
{
|
{
|
||||||
qRegisterMetaType<OAuthAccessToken>("OAuthAccessToken");
|
qRegisterMetaType<OAuthAccessToken>("OAuthAccessToken");
|
||||||
qRegisterMetaTypeStreamOperators<OAuthAccessToken>("OAuthAccessToken");
|
qRegisterMetaTypeStreamOperators<OAuthAccessToken>("OAuthAccessToken");
|
||||||
|
@ -47,27 +47,13 @@ AccountManager::AccountManager() :
|
||||||
|
|
||||||
qRegisterMetaType<QNetworkAccessManager::Operation>("QNetworkAccessManager::Operation");
|
qRegisterMetaType<QNetworkAccessManager::Operation>("QNetworkAccessManager::Operation");
|
||||||
qRegisterMetaType<JSONCallbackParameters>("JSONCallbackParameters");
|
qRegisterMetaType<JSONCallbackParameters>("JSONCallbackParameters");
|
||||||
|
|
||||||
// check if there are existing access tokens to load from settings
|
|
||||||
QSettings settings;
|
|
||||||
settings.beginGroup(ACCOUNTS_GROUP);
|
|
||||||
|
|
||||||
foreach(const QString& key, settings.allKeys()) {
|
|
||||||
// take a key copy to perform the double slash replacement
|
|
||||||
QString keyCopy(key);
|
|
||||||
QUrl keyURL(keyCopy.replace("slashslash", "//"));
|
|
||||||
|
|
||||||
// pull out the stored access token and put it in our in memory array
|
|
||||||
_accounts.insert(keyURL, settings.value(key).value<DataServerAccountInfo>());
|
|
||||||
qDebug() << "Found a data-server access token for" << qPrintable(keyURL.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString DOUBLE_SLASH_SUBSTITUTE = "slashslash";
|
const QString DOUBLE_SLASH_SUBSTITUTE = "slashslash";
|
||||||
|
|
||||||
void AccountManager::logout() {
|
void AccountManager::logout() {
|
||||||
// a logout means we want to delete the DataServerAccountInfo we currently have for this URL, in-memory and in file
|
// a logout means we want to delete the DataServerAccountInfo we currently have for this URL, in-memory and in file
|
||||||
_accounts.remove(_authURL);
|
_accountInfo = DataServerAccountInfo();
|
||||||
|
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
settings.beginGroup(ACCOUNTS_GROUP);
|
settings.beginGroup(ACCOUNTS_GROUP);
|
||||||
|
@ -80,7 +66,6 @@ void AccountManager::logout() {
|
||||||
emit logoutComplete();
|
emit logoutComplete();
|
||||||
// the username has changed to blank
|
// the username has changed to blank
|
||||||
emit usernameChanged(QString());
|
emit usernameChanged(QString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccountManager::setAuthURL(const QUrl& authURL) {
|
void AccountManager::setAuthURL(const QUrl& authURL) {
|
||||||
|
@ -90,6 +75,22 @@ void AccountManager::setAuthURL(const QUrl& authURL) {
|
||||||
qDebug() << "URL for node authentication has been changed to" << qPrintable(_authURL.toString());
|
qDebug() << "URL for node authentication has been changed to" << qPrintable(_authURL.toString());
|
||||||
qDebug() << "Re-setting authentication flow.";
|
qDebug() << "Re-setting authentication flow.";
|
||||||
|
|
||||||
|
// check if there are existing access tokens to load from settings
|
||||||
|
QSettings settings;
|
||||||
|
settings.beginGroup(ACCOUNTS_GROUP);
|
||||||
|
|
||||||
|
foreach(const QString& key, settings.allKeys()) {
|
||||||
|
// take a key copy to perform the double slash replacement
|
||||||
|
QString keyCopy(key);
|
||||||
|
QUrl keyURL(keyCopy.replace("slashslash", "//"));
|
||||||
|
|
||||||
|
if (keyURL == _authURL) {
|
||||||
|
// pull out the stored access token and store it in memory
|
||||||
|
_accountInfo = settings.value(key).value<DataServerAccountInfo>();
|
||||||
|
qDebug() << "Found a data-server access token for" << qPrintable(keyURL.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// tell listeners that the auth endpoint has changed
|
// tell listeners that the auth endpoint has changed
|
||||||
emit authEndpointChanged();
|
emit authEndpointChanged();
|
||||||
}
|
}
|
||||||
|
@ -111,7 +112,7 @@ void AccountManager::invokedRequest(const QString& path, QNetworkAccessManager::
|
||||||
|
|
||||||
QUrl requestURL = _authURL;
|
QUrl requestURL = _authURL;
|
||||||
requestURL.setPath(path);
|
requestURL.setPath(path);
|
||||||
requestURL.setQuery("access_token=" + _accounts.value(_authURL).getAccessToken().token);
|
requestURL.setQuery("access_token=" + _accountInfo.getAccessToken().token);
|
||||||
|
|
||||||
authenticatedRequest.setUrl(requestURL);
|
authenticatedRequest.setUrl(requestURL);
|
||||||
|
|
||||||
|
@ -202,9 +203,8 @@ void AccountManager::passErrorToCallback(QNetworkReply::NetworkError errorCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AccountManager::hasValidAccessToken() {
|
bool AccountManager::hasValidAccessToken() {
|
||||||
DataServerAccountInfo accountInfo = _accounts.value(_authURL);
|
|
||||||
|
|
||||||
if (accountInfo.getAccessToken().token.isEmpty() || accountInfo.getAccessToken().isExpired()) {
|
if (_accountInfo.getAccessToken().token.isEmpty() || _accountInfo.getAccessToken().isExpired()) {
|
||||||
if (VERBOSE_HTTP_REQUEST_DEBUGGING) {
|
if (VERBOSE_HTTP_REQUEST_DEBUGGING) {
|
||||||
qDebug() << "An access token is required for requests to" << qPrintable(_authURL.toString());
|
qDebug() << "An access token is required for requests to" << qPrintable(_authURL.toString());
|
||||||
}
|
}
|
||||||
|
@ -266,18 +266,17 @@ void AccountManager::requestFinished() {
|
||||||
|
|
||||||
qDebug() << "Storing an account with access-token for" << qPrintable(rootURL.toString());
|
qDebug() << "Storing an account with access-token for" << qPrintable(rootURL.toString());
|
||||||
|
|
||||||
DataServerAccountInfo freshAccountInfo(rootObject);
|
_accountInfo = DataServerAccountInfo(rootObject);
|
||||||
_accounts.insert(rootURL, freshAccountInfo);
|
|
||||||
|
|
||||||
emit loginComplete(rootURL);
|
emit loginComplete(rootURL);
|
||||||
// the username has changed to whatever came back
|
// the username has changed to whatever came back
|
||||||
emit usernameChanged(freshAccountInfo.getUsername());
|
emit usernameChanged(_accountInfo.getUsername());
|
||||||
|
|
||||||
// store this access token into the local settings
|
// store this access token into the local settings
|
||||||
QSettings localSettings;
|
QSettings localSettings;
|
||||||
localSettings.beginGroup(ACCOUNTS_GROUP);
|
localSettings.beginGroup(ACCOUNTS_GROUP);
|
||||||
localSettings.setValue(rootURL.toString().replace("//", DOUBLE_SLASH_SUBSTITUTE),
|
localSettings.setValue(rootURL.toString().replace("//", DOUBLE_SLASH_SUBSTITUTE),
|
||||||
QVariant::fromValue(freshAccountInfo));
|
QVariant::fromValue(_accountInfo));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO: error handling
|
// TODO: error handling
|
||||||
|
|
|
@ -51,7 +51,7 @@ public:
|
||||||
|
|
||||||
void requestAccessToken(const QString& login, const QString& password);
|
void requestAccessToken(const QString& login, const QString& password);
|
||||||
|
|
||||||
QString getUsername() const { return _accounts[_authURL].getUsername(); }
|
QString getUsername() const { return _accountInfo.getUsername(); }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void requestFinished();
|
void requestFinished();
|
||||||
|
@ -78,7 +78,7 @@ private:
|
||||||
QNetworkAccessManager _networkAccessManager;
|
QNetworkAccessManager _networkAccessManager;
|
||||||
QMap<QNetworkReply*, JSONCallbackParameters> _pendingCallbackMap;
|
QMap<QNetworkReply*, JSONCallbackParameters> _pendingCallbackMap;
|
||||||
|
|
||||||
QMap<QUrl, DataServerAccountInfo> _accounts;
|
DataServerAccountInfo _accountInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(__hifi__AccountManager__) */
|
#endif /* defined(__hifi__AccountManager__) */
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
OAuthAccessToken::OAuthAccessToken() :
|
OAuthAccessToken::OAuthAccessToken() :
|
||||||
token(),
|
token(),
|
||||||
refreshToken(),
|
refreshToken(),
|
||||||
expiryTimestamp(),
|
expiryTimestamp(0),
|
||||||
tokenType()
|
tokenType()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue