Add cookie saving/restoring to avoid need for SSO login for each QGIS session#766
Add cookie saving/restoring to avoid need for SSO login for each QGIS session#766nirvn wants to merge 3 commits into
Conversation
suricactus
left a comment
There was a problem hiding this comment.
Code looks good, I leave @lukasgraf for the final review.
| self.restore_cookies() | ||
|
|
||
| def restore_cookies(self): | ||
| raw_cookies = self.preferences.value("qfieldCloudCookies") |
There was a problem hiding this comment.
So, after switching the previous version of my qfieldsync plugin to this branch, I get the following traceback on QGIS launch:
NameError: QFieldSync has no setting qfieldCloudCookies
Traceback (most recent call last):
File "/Applications/QGIS-final-3_44_4.app/Contents/Frameworks/lib/python3.12/site-packages/qgis/utils.py", line 478, in _startPlugin
plugins[packageName] = package.classFactory(iface)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/lukasgraf/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/qfieldsync/__init__.py", line 58, in classFactory
return QFieldSync(iface)
^^^^^^^^^^^^^^^^^
File "/Users/lukasgraf/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/qfieldsync/qfield_sync.py", line 132, in __init__
self.network_manager = CloudNetworkAccessManager(self.iface.mainWindow())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/lukasgraf/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/qfieldsync/core/cloud_api.py", line 253, in __init__
self.restore_cookies()
File "/Users/lukasgraf/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/qfieldsync/core/cloud_api.py", line 256, in restore_cookies
raw_cookies = self.preferences.value("qfieldCloudCookies")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/lukasgraf/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/qfieldsync/setting_manager/setting_manager.py", line 53, in value
raise NameError('%s has no setting %s' % (self.plugin_name, setting_name))
NameError: QFieldSync has no setting qfieldCloudCookiesIs there possibly some sort of preferences migration that the plugin would need to perform, or do we need to make the self.preferences.value("qfieldCloudCookies") access more defensive, dealing with the fact that that preference key might not exist?
It looks like the new preferences key isn't even added in preferences.py?
There was a problem hiding this comment.
Oh yeah I forgot to commit that file.
There was a problem hiding this comment.
It's pretty straightforward though. We add a global scope string list preference with an empty array as default value
There was a problem hiding this comment.
So even when I make that change manually, I can't currently get a successful signin.
I get varying errors displayed in red in the QFS UI, like Expecting value: line 1 column 1 (char 0), or sometimes a truncated dump of HTML, with no immediately obvious way to tell what's happening.
In this version, with the current state in my profile, QFS is not allowing me to really test this change. I need to focus on some other stuff first, and come back later to review this.
There was a problem hiding this comment.
@lukasgraf , no worries, I'll reach out when that's fixed
lukasgraf
left a comment
There was a problem hiding this comment.
Unfortunately, this doesn't work as expected for me.
The cookies that are getting saved and restored are always empty ([]). They are present in the cookie jar at the beginning of _on_get_user_info_finished(), but they get emptied as soon as the self.get_file() for the avatar has finished executing.
The reason for that seems to be this call to self._clear_cloud_cookies()in cloud_get().
|
@lukasgraf , OK, another round. While I don't have the proper setup locally to test things, I am seeing non-SSO cookie saved and restored across sessions. So my level of confidence is increasing ;) |
|
@nirvn what is the cookie name? |
|
@suricactus , the one I see is sessionid |
@suricactus , @lukasgraf , as discussed over Google Chat.
@lukasgraf , could you give this a try with your local instance?