gtg icon indicating copy to clipboard operation
gtg copied to clipboard

CalDAV OAUTH2 authentication support

Open azmeuk opened this issue 2 years ago • 0 comments

Some DAV providers disable the Basic authentication method (i.e. username+password) in favor of the Bearer method (i.e. tokens).

Trying to connect to such a provider with GTG results in this traceback being displayed, but no in-app message indicating something is going wrong:

Traceback
Exception in thread Thread-1 (__backend_startup):
Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.10/site-packages/GTG/core/datastore.py", line 499, in __backend_startup
    backend.start_get_tasks()
  File "/usr/lib/python3.10/site-packages/GTG/core/datastore.py", line 694, in start_get_tasks
    self.backend.start_get_tasks()
  File "/usr/lib/python3.10/site-packages/GTG/core/interruptible.py", line 38, in new
    return fn(*args)
  File "/usr/lib/python3.10/site-packages/GTG/backends/periodic_import_backend.py", line 79, in start_get_tasks
    self._start_get_tasks()
  File "/usr/lib/python3.10/site-packages/GTG/backends/periodic_import_backend.py", line 98, in _start_get_tasks
    self.do_periodic_import()
  File "/usr/lib/python3.10/site-packages/GTG/core/interruptible.py", line 38, in new
    return fn(*args)
  File "/usr/lib/python3.10/site-packages/GTG/backends/backend_caldav.py", line 111, in do_periodic_import
    self._do_periodic_import()
  File "/usr/lib/python3.10/site-packages/GTG/backends/backend_caldav.py", line 139, in _do_periodic_import
    self._refresh_calendar_list()
  File "/usr/lib/python3.10/site-packages/GTG/backends/backend_caldav.py", line 218, in _refresh_calendar_list
    principal = self._dav_client.principal()
  File "/usr/lib/python3.10/site-packages/caldav/davclient.py", line 362, in principal
    self._principal = Principal(client=self, *largs, **kwargs)
  File "/usr/lib/python3.10/site-packages/caldav/objects.py", line 404, in __init__
    cup = self.get_property(dav.CurrentUserPrincipal())
  File "/usr/lib/python3.10/site-packages/caldav/objects.py", line 175, in get_property
    foo = self.get_properties([prop], **passthrough)
  File "/usr/lib/python3.10/site-packages/caldav/objects.py", line 198, in get_properties
    response = self._query_properties(props, depth)
  File "/usr/lib/python3.10/site-packages/caldav/objects.py", line 142, in _query_properties
    return self._query(root, depth)
  File "/usr/lib/python3.10/site-packages/caldav/objects.py", line 160, in _query
    ret = getattr(self.client, query_method)(
  File "/usr/lib/python3.10/site-packages/caldav/davclient.py", line 410, in propfind
    return self.request(url or self.url, "PROPFIND", props,
  File "/usr/lib/python3.10/site-packages/caldav/davclient.py", line 557, in request
    raise NotImplementedError("Auth method %s not supported yet" % auth_type)
NotImplementedError: Auth method bearer not supported yet

Fixing this probably depends on python-caldav OAUTH support, but it has not been implemented yet. However some UX work would be needed on the GTG side then, because retrieving a token implies to open a web view and let the user connect to their identity provider.

I suggest to:

  • display a comprehensible error message in the application when this NotImplementedError is met
  • allow CalDAV OAUTH2 authentication support when it is ready on the caldav lib side by:
    • detecting the allowed authentication methods from the www-authenticate header returned by the DAV server
    • displaying either the user/password form, or an OAUTH2 webview, or both, depending on the authentication methods supported by the server.

What do you think?

azmeuk avatar Jun 29 '22 08:06 azmeuk