mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
store access tokens in settings so re-log not required
This commit is contained in:
parent
ca6dfa58a6
commit
3199f1a3e4
4 changed files with 28 additions and 3 deletions
|
@ -25,11 +25,15 @@ AccountManager& AccountManager::getInstance() {
|
||||||
return sharedInstance;
|
return sharedInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(OAuthAccessToken)
|
||||||
|
|
||||||
AccountManager::AccountManager() :
|
AccountManager::AccountManager() :
|
||||||
_rootURL(),
|
_rootURL(),
|
||||||
_username(),
|
_username(),
|
||||||
_networkAccessManager(NULL)
|
_networkAccessManager(NULL)
|
||||||
{
|
{
|
||||||
|
qRegisterMetaType<OAuthAccessToken>("OAuthAccessToken");
|
||||||
|
qRegisterMetaTypeStreamOperators<OAuthAccessToken>("OAuthAccessToken");
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccountManager::authenticatedGetRequest(const QString& path, const QObject *successReceiver, const char *successMethod,
|
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() {
|
void AccountManager::requestFinished() {
|
||||||
QNetworkReply* requestReply = reinterpret_cast<QNetworkReply*>(sender());
|
QNetworkReply* requestReply = reinterpret_cast<QNetworkReply*>(sender());
|
||||||
|
|
||||||
|
@ -117,7 +122,15 @@ void AccountManager::requestFinished() {
|
||||||
|
|
||||||
qDebug() << "Storing an access token for" << rootURL;
|
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 {
|
} else {
|
||||||
// TODO: error handling
|
// TODO: error handling
|
||||||
|
|
|
@ -33,7 +33,6 @@ void DomainInfo::reset() {
|
||||||
|
|
||||||
void DomainInfo::parseAuthInformationFromJsonObject(const QJsonObject& jsonObject) {
|
void DomainInfo::parseAuthInformationFromJsonObject(const QJsonObject& jsonObject) {
|
||||||
_connectionSecret = QUuid(jsonObject["connection_uuid"].toString());
|
_connectionSecret = QUuid(jsonObject["connection_uuid"].toString());
|
||||||
qDebug() << jsonObject["registration_token"];
|
|
||||||
_registrationToken = QByteArray::fromHex(jsonObject["registration_token"].toString().toUtf8());
|
_registrationToken = QByteArray::fromHex(jsonObject["registration_token"].toString().toUtf8());
|
||||||
_publicKey = jsonObject["public_key"].toString();
|
_publicKey = jsonObject["public_key"].toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,4 +48,14 @@ void OAuthAccessToken::swap(OAuthAccessToken& otherToken) {
|
||||||
swap(refreshToken, otherToken.refreshToken);
|
swap(refreshToken, otherToken.refreshToken);
|
||||||
swap(expiryTimestamp, otherToken.expiryTimestamp);
|
swap(expiryTimestamp, otherToken.expiryTimestamp);
|
||||||
swap(tokenType, otherToken.tokenType);
|
swap(tokenType, otherToken.tokenType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -27,6 +27,9 @@ public:
|
||||||
QString refreshToken;
|
QString refreshToken;
|
||||||
quint64 expiryTimestamp;
|
quint64 expiryTimestamp;
|
||||||
QString tokenType;
|
QString tokenType;
|
||||||
|
|
||||||
|
friend QDataStream& operator<<(QDataStream &out, const OAuthAccessToken& token);
|
||||||
|
friend QDataStream& operator>>(QDataStream &in, OAuthAccessToken& token);
|
||||||
private:
|
private:
|
||||||
void swap(OAuthAccessToken& otherToken);
|
void swap(OAuthAccessToken& otherToken);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue