diff --git a/libraries/shared/src/AccountManager.cpp b/libraries/shared/src/AccountManager.cpp index d71636a483..69c47e1ef8 100644 --- a/libraries/shared/src/AccountManager.cpp +++ b/libraries/shared/src/AccountManager.cpp @@ -25,11 +25,15 @@ AccountManager& AccountManager::getInstance() { return sharedInstance; } +Q_DECLARE_METATYPE(OAuthAccessToken) + AccountManager::AccountManager() : _rootURL(), _username(), _networkAccessManager(NULL) { + qRegisterMetaType("OAuthAccessToken"); + qRegisterMetaTypeStreamOperators("OAuthAccessToken"); } void AccountManager::authenticatedGetRequest(const QString& path, const QObject *successReceiver, const char *successMethod, @@ -97,6 +101,7 @@ void AccountManager::requestAccessToken(const QString& username, const QString& } } + void AccountManager::requestFinished() { QNetworkReply* requestReply = reinterpret_cast(sender()); @@ -117,7 +122,15 @@ void AccountManager::requestFinished() { qDebug() << "Storing an access token for" << rootURL; - _accessTokens.insert(rootURL, OAuthAccessToken(rootObject)); + OAuthAccessToken freshAccessToken(rootObject); + _accessTokens.insert(rootURL, freshAccessToken); + + // store this access token into the local settings + QSettings localSettings; + const QString ACCOUNT_TOKEN_GROUP = "tokens"; + localSettings.beginGroup(ACCOUNT_TOKEN_GROUP); + + localSettings.setValue(rootURL.toString(), qVariantFromValue(freshAccessToken)); } } else { // TODO: error handling diff --git a/libraries/shared/src/DomainInfo.cpp b/libraries/shared/src/DomainInfo.cpp index 51f664757f..8eb7032011 100644 --- a/libraries/shared/src/DomainInfo.cpp +++ b/libraries/shared/src/DomainInfo.cpp @@ -33,7 +33,6 @@ void DomainInfo::reset() { void DomainInfo::parseAuthInformationFromJsonObject(const QJsonObject& jsonObject) { _connectionSecret = QUuid(jsonObject["connection_uuid"].toString()); - qDebug() << jsonObject["registration_token"]; _registrationToken = QByteArray::fromHex(jsonObject["registration_token"].toString().toUtf8()); _publicKey = jsonObject["public_key"].toString(); } diff --git a/libraries/shared/src/OAuthAccessToken.cpp b/libraries/shared/src/OAuthAccessToken.cpp index fe2dd14329..7852a14878 100644 --- a/libraries/shared/src/OAuthAccessToken.cpp +++ b/libraries/shared/src/OAuthAccessToken.cpp @@ -48,4 +48,14 @@ void OAuthAccessToken::swap(OAuthAccessToken& otherToken) { swap(refreshToken, otherToken.refreshToken); swap(expiryTimestamp, otherToken.expiryTimestamp); swap(tokenType, otherToken.tokenType); -} \ No newline at end of file +} + +QDataStream& operator<<(QDataStream &out, const OAuthAccessToken& token) { + out << token.token << token.expiryTimestamp << token.tokenType << token.refreshToken; + return out; +} + +QDataStream& operator>>(QDataStream &in, OAuthAccessToken& token) { + in >> token.token >> token.expiryTimestamp >> token.tokenType >> token.refreshToken; + return in; +} diff --git a/libraries/shared/src/OAuthAccessToken.h b/libraries/shared/src/OAuthAccessToken.h index a7fd7fed41..3b61a35923 100644 --- a/libraries/shared/src/OAuthAccessToken.h +++ b/libraries/shared/src/OAuthAccessToken.h @@ -27,6 +27,9 @@ public: QString refreshToken; quint64 expiryTimestamp; QString tokenType; + + friend QDataStream& operator<<(QDataStream &out, const OAuthAccessToken& token); + friend QDataStream& operator>>(QDataStream &in, OAuthAccessToken& token); private: void swap(OAuthAccessToken& otherToken); };