Skip to content

Commit

Permalink
Add auth token setting
Browse files Browse the repository at this point in the history
Allows gtimelog to read from protected remote task list

Signed-off-by: NickWingate <nicholas.wingate03@gmail.com>
  • Loading branch information
NickWingate committed Apr 28, 2024
1 parent cc4ed57 commit 3ac376d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
Binary file modified src/gtimelog/data/gschemas.compiled
Binary file not shown.
6 changes: 6 additions & 0 deletions src/gtimelog/data/org.gtimelog.gschema.xml
Expand Up @@ -157,6 +157,12 @@
<description>URL for editing tasks for the task pane. Will be opened in a browser window if the user asks to edit tasks.</description>
</key>

<key name="remote-auth-header" type="s">
<default>""</default>
<summary>Remote authentication token</summary>
<description>Authentication token for when task-list-url is protected</description>
</key>

<key name="gtk-completion" type="b">
<default>true</default>
<summary>Use completion</summary>
Expand Down
6 changes: 6 additions & 0 deletions src/gtimelog/main.py
Expand Up @@ -659,6 +659,7 @@ def load_settings(self):
self.gsettings.bind('gtk-completion', self.task_entry, 'gtk-completion-enabled', Gio.SettingsBindFlags.DEFAULT)
self.gsettings.connect('changed::remote-task-list', self.load_tasks)
self.gsettings.connect('changed::task-list-url', self.load_tasks)
self.gsettings.connect('changed::remote-auth-header', self.load_tasks)
self.gsettings.connect('changed::task-list-edit-url', self.update_edit_tasks_availability)
self.gsettings.connect('changed::virtual-midnight', self.virtual_midnight_changed)
self.update_edit_tasks_availability()
Expand Down Expand Up @@ -690,6 +691,7 @@ def load_settings(self):
self.gsettings.set_string('list-email', old_settings.email)
self.gsettings.set_string('report-style', old_settings.report_style)
self.gsettings.set_string('task-list-url', old_settings.task_list_url)
self.gsettings.set_string('remote-auth-header', old_settings.auth_header)
self.gsettings.set_boolean('remote-task-list', bool(old_settings.task_list_url))
for arg in old_settings.edit_task_list_cmd.split():
if arg.startswith(('http://', 'https://')):
Expand Down Expand Up @@ -774,6 +776,7 @@ def download_tasks(self):
self.cancel_tasks_download(hide=False)

url = self.gsettings.get_string('task-list-url')
auth_header = self.gsettings.get_string('remote-auth-header')
if not url:
log.debug("Not downloading tasks: URL not specified")
return
Expand All @@ -788,6 +791,9 @@ def download_tasks(self):
message = Soup.Message.new('GET', url)
self._download = (message, url)
message.connect('authenticate', authenticator.http_auth_cb)
if (auth_header and not auth_header.isspace()):
message.get_request_headers().append('Authorization', auth_header)

soup_session.send_and_read_async(
message,
GLib.PRIORITY_DEFAULT,
Expand Down
1 change: 1 addition & 0 deletions src/gtimelog/settings.py
Expand Up @@ -40,6 +40,7 @@ class Settings(object):
virtual_midnight = datetime.time(2, 0)

task_list_url = ''
auth_header = ''
edit_task_list_cmd = ''

show_office_hours = True
Expand Down

0 comments on commit 3ac376d

Please sign in to comment.