Skip to content

Commit

Permalink
Use Gnome Online Accounts for getting credentials (optional)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvladus committed Jan 11, 2024
1 parent bbf1d8a commit 9602fcf
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 4 deletions.
41 changes: 41 additions & 0 deletions errands/utils/goa.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2023-2024 Vlad Krupinskii <mrvladus@yandex.ru>
# SPDX-License-Identifier: MIT

from errands.utils.logging import Log


def get_goa_credentials(acc_name: str) -> dict[str, str] | None:
"""
If Gnome Online Accounts is installed, try to get account info.
Only for password based account yet.
"""

try:
import gi

gi.require_version("Goa", "1.0")
from gi.repository import Goa
except (ValueError, ModuleNotFoundError):
Log.debug("Gnome Online Accounts is not installed. Skipping...")
return None

client: Goa.Client = Goa.Client.new_sync(None)
accounts: list[Goa.ObjectProxy] = client.get_accounts()
for account in accounts:
acc: Goa.AccountProxy = account.get_account()
name: str = acc.get_cached_property("ProviderName").get_string()
if name == acc_name:
Log.debug(f"GOA: Getting data for {acc_name}")
username, url = (
acc.get_cached_property("PresentationIdentity").get_string().split("@")
)
password = account.get_password_based().call_get_password_sync(
arg_id=acc.get_cached_property("Id").get_string()
)
result: dict[str, str] = {
"url": url,
"username": username,
"password": password,
}
return result
return None
1 change: 0 additions & 1 deletion errands/utils/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# SPDX-License-Identifier: MIT

import datetime, urllib3
from typing import Callable
from caldav import Calendar, DAVClient, Principal, Todo
from caldav.elements import dav
from gi.repository import Adw, GLib
Expand Down
12 changes: 12 additions & 0 deletions errands/widgets/preferences.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2023 Vlad Krupinskii <mrvladus@yandex.ru>
# SPDX-License-Identifier: MIT

from errands.utils.goa import get_goa_credentials
from gi.repository import Adw, Gtk
from errands.utils.sync import Sync
from errands.utils.gsettings import GSettings
Expand Down Expand Up @@ -189,6 +190,17 @@ def _setup_sync(self) -> None:
with self.sync_password.freeze_notify():
self.sync_password.props.text = password if password else ""

# Fill out forms from Gnome Online Accounts if needed
acc_name: str = self.sync_providers.props.selected_item.props.string
data: dict[str, str] | None = get_goa_credentials(acc_name)
if data:
if not GSettings.get("sync-url"):
self.sync_url.set_text(data["url"])
if not GSettings.get("sync-username"):
self.sync_username.set_text(data["username"])
if not GSettings.get_secret(acc_name):
self.sync_password.set_text(data["password"])

def on_sync_provider_selected(self, *_) -> None:
self._setup_sync()

Expand Down
38 changes: 35 additions & 3 deletions io.github.mrvladus.List.Devel.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"app-id": "io.github.mrvladus.List.Devel",
"id": "io.github.mrvladus.List.Devel",
"runtime": "org.gnome.Platform",
"runtime-version": "45",
"sdk": "org.gnome.Sdk",
Expand All @@ -10,12 +10,44 @@
"--socket=fallback-x11",
"--share=ipc",
"--share=network",
"--talk-name=org.freedesktop.secrets"
"--talk-name=org.freedesktop.secrets",
"--talk-name=org.gnome.OnlineAccounts"
],
"cleanup": [
"/lib/debug"
"/lib/debug",
"/include",
"/lib/pkgconfig",
"/man",
"/share/aclocal",
"/share/gtk-doc",
"/share/man",
"/share/pkgconfig",
"/share/vala",
"*.la",
"*.a"
],
"modules": [
{
"name": "gnome-online-accounts",
"buildsystem": "meson",
"config-opts": [
"-Dgoabackend=false",
"-Dexchange=false",
"-Dgoogle=false",
"-Dimap_smtp=false",
"-Dwebdav=false",
"-Dkerberos=false",
"-Dwindows_live=false",
"-Dvapi=false"
],
"sources": [
{
"type": "git",
"url": "https://gitlab.gnome.org/GNOME/gnome-online-accounts.git",
"branch": "master"
}
]
},
"build-aux/python3-modules.json",
{
"name": "errands",
Expand Down

0 comments on commit 9602fcf

Please sign in to comment.