diff options
author | Martin Rotter <rotter.martinos@gmail.com> | 2017-10-04 17:01:28 +0200 |
---|---|---|
committer | Martin Rotter <rotter.martinos@gmail.com> | 2017-10-05 10:24:12 +0000 |
commit | d811ebc6c6e83b33d765664328da5c8c6f518f66 (patch) | |
tree | 9b9c12c95821de43228919133a7350f97f58fea0 /src | |
parent | c9893adea875610d5e325934ad9681bc8ca17176 (diff) |
Add public API for getting/setting OAuth 2.0 refresh tokensv5.10.0-beta3v5.10.0-beta2
Refresh tokens were not publicly accessible from QAbstractOAuth2 class.
So user was unable to (etc.) save refresh token to database. Refresh
tokens are meant to have longer lifespan than access tokens (as hinted in
https://tools.ietf.org/html/rfc6749#section-1.5) and they even
do not have to expire at all, so that it is very expected to have ability
of saving/restoring them to classes representing OAuth 2.0 sessions. Also
added some documentation.
[ChangeLog][QAbstractOAuth2] Added ability to get/set OAuth 2.0
refresh token via public API, so that user can store existing
refresh tokens and reuse them later.
Task-number: QTBUG-63357
Change-Id: I93ea279e12caed3791b147d9c37ab48d01b2bf42
Reviewed-by: Martin Rotter <rotter.martinos@gmail.com>
Reviewed-by: Erik Larsson <erik@ortogonal.com>
Reviewed-by: Jesus Fernandez <Jesus.Fernandez@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/oauth/qabstractoauth2.cpp | 28 | ||||
-rw-r--r-- | src/oauth/qabstractoauth2.h | 3 |
2 files changed, 31 insertions, 0 deletions
diff --git a/src/oauth/qabstractoauth2.cpp b/src/oauth/qabstractoauth2.cpp index d70191b..49c8f03 100644 --- a/src/oauth/qabstractoauth2.cpp +++ b/src/oauth/qabstractoauth2.cpp @@ -388,6 +388,34 @@ QDateTime QAbstractOAuth2::expirationAt() const return d->expiresAt; } +/*! + \brief Gets the current refresh token. + + Refresh tokens usually have longer lifespans than access tokens, + so it makes sense to save them for later use. + + Returns the current refresh token or an empty string, if + there is no refresh token available. +*/ +QString QAbstractOAuth2::refreshToken() const +{ + Q_D(const QAbstractOAuth2); + return d->refreshToken; +} + +/*! + \brief Sets the new refresh token \a refreshToken to be used. + + A custom refresh token can be used to refresh the access token via this method and then + the access token can be refreshed via QOAuth2AuthorizationCodeFlow::refreshAccessToken(). + +*/ +void QAbstractOAuth2::setRefreshToken(const QString &refreshToken) +{ + Q_D(QAbstractOAuth2); + d->refreshToken = refreshToken; +} + QT_END_NAMESPACE #endif // QT_NO_HTTP diff --git a/src/oauth/qabstractoauth2.h b/src/oauth/qabstractoauth2.h index c3bbd5a..0f600b2 100644 --- a/src/oauth/qabstractoauth2.h +++ b/src/oauth/qabstractoauth2.h @@ -86,6 +86,9 @@ public: QDateTime expirationAt() const; + QString refreshToken() const; + void setRefreshToken(const QString &refreshToken); + Q_SIGNALS: void scopeChanged(const QString &scope); void userAgentChanged(const QString &userAgent); |