aboutsummaryrefslogtreecommitdiffstats
path: root/examples/networkauth
diff options
context:
space:
mode:
authorShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2022-02-11 14:12:20 +0100
committerShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2022-02-22 11:38:33 +0100
commit535a781d534f4c9d102342a9813528e48c576ffd (patch)
tree2c31bb819966705d6f1d8fee36c1a804ebfb3848 /examples/networkauth
parent19eb0b01f4031c7897f98c73e178636b56bc7fb1 (diff)
QAbstractOAuth - add setModifyParametersFunction
- create bindigns for setModifyParametersFunction - reddit example modified to include setModifyParametersFunction() Pick-to: 6.2 Task-number: PYSIDE-1815 Change-Id: If3573df070483f22cc46d9f95f688299e9ece420 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'examples/networkauth')
-rw-r--r--examples/networkauth/redditclient/redditwrapper.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/examples/networkauth/redditclient/redditwrapper.py b/examples/networkauth/redditclient/redditwrapper.py
index e069fdeb0..19dddf654 100644
--- a/examples/networkauth/redditclient/redditwrapper.py
+++ b/examples/networkauth/redditclient/redditwrapper.py
@@ -56,7 +56,6 @@ NEW_URL = "https://oauth.reddit.com/new"
HOT_URL = "https://oauth.reddit.com/hot"
LIVE_THREADS_URL = "https://oauth.reddit.com/live/XXXX/about.json"
-
class RedditWrapper(QObject):
authenticated = Signal()
@@ -66,14 +65,24 @@ class RedditWrapper(QObject):
super().__init__(parent)
self._oauth2 = QOAuth2AuthorizationCodeFlow()
- self._oauth2.statusChanged.connect(self.status_changed)
- self._oauth2.authorizeWithBrowser.connect(QDesktopServices.openUrl)
self._oauth2.setClientIdentifier(clientIdentifier)
self._reply_handler = QOAuthHttpServerReplyHandler(1337, self)
self._oauth2.setReplyHandler(self._reply_handler)
self._oauth2.setAuthorizationUrl(QUrl(AUTHORIZATION_URL))
self._oauth2.setAccessTokenUrl(QUrl(ACCESSTOKEN_URL))
self._oauth2.setScope("identity read")
+ self._permanent = True
+
+ # connect to slots
+ self._oauth2.statusChanged.connect(self.status_changed)
+ self._oauth2.authorizeWithBrowser.connect(QDesktopServices.openUrl)
+
+ def modify_parameters_function(stage, parameters):
+ if stage == QAbstractOAuth.Stage.RequestingAuthorization and self.permanent:
+ parameters["duration"] = "permanent"
+ return parameters
+
+ self._oauth2.setModifyParametersFunction(modify_parameters_function)
@Slot()
def status_changed(self, status):
@@ -84,6 +93,14 @@ class RedditWrapper(QObject):
print("Getting hot threads...")
return self._oauth2.get(QUrl(HOT_URL))
+ @property
+ def permanent(self):
+ return self._permanent
+
+ @permanent.setter
+ def permanent(self, value: bool):
+ self._permanent = value
+
def grant(self):
self._oauth2.grant()