Skip to content

Add cookie saving/restoring to avoid need for SSO login for each QGIS session#766

Open
nirvn wants to merge 3 commits into
masterfrom
sso_cookies
Open

Add cookie saving/restoring to avoid need for SSO login for each QGIS session#766
nirvn wants to merge 3 commits into
masterfrom
sso_cookies

Conversation

@nirvn
Copy link
Copy Markdown
Member

@nirvn nirvn commented Apr 22, 2026

@suricactus , @lukasgraf , as discussed over Google Chat.

@lukasgraf , could you give this a try with your local instance?

Copy link
Copy Markdown
Collaborator

@suricactus suricactus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good, I leave @lukasgraf for the final review.

self.restore_cookies()

def restore_cookies(self):
raw_cookies = self.preferences.value("qfieldCloudCookies")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 qfieldCloudCookies

Is 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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah I forgot to commit that file.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's pretty straightforward though. We add a global scope string list preference with an empty array as default value

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lukasgraf , no worries, I'll reach out when that's fixed

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lukasgraf , missing bit added.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lukasgraf ping

@nirvn nirvn requested a review from lukasgraf April 26, 2026 11:22
Copy link
Copy Markdown

@lukasgraf lukasgraf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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().

@nirvn
Copy link
Copy Markdown
Member Author

nirvn commented May 14, 2026

@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 ;)

@suricactus
Copy link
Copy Markdown
Collaborator

@nirvn what is the cookie name?

@nirvn
Copy link
Copy Markdown
Member Author

nirvn commented May 14, 2026

@suricactus , the one I see is sessionid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants