diff --git a/CHANGELOG.md b/CHANGELOG.md index ab7f52a..883a8ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,20 +1,12 @@ # Changelog -## [0.3.8a2](https://github.com/OpenVoiceOS/ovos-utils/tree/0.3.8a2) (2024-11-19) +## [0.4.1a1](https://github.com/OpenVoiceOS/ovos-utils/tree/0.4.1a1) (2024-11-20) -[Full Changelog](https://github.com/OpenVoiceOS/ovos-utils/compare/0.3.8a1...0.3.8a2) +[Full Changelog](https://github.com/OpenVoiceOS/ovos-utils/compare/0.4.0...0.4.1a1) **Merged pull requests:** -- feature: geolocation utils extracted from backend-client [\#296](https://github.com/OpenVoiceOS/ovos-utils/pull/296) ([JarbasAl](https://github.com/JarbasAl)) - -## [0.3.8a1](https://github.com/OpenVoiceOS/ovos-utils/tree/0.3.8a1) (2024-11-11) - -[Full Changelog](https://github.com/OpenVoiceOS/ovos-utils/compare/0.3.7...0.3.8a1) - -**Merged pull requests:** - -- Update ovos-bus-client requirement from \<1.0.0,\>=0.0.8 to \>=0.0.8,\<2.0.0 in /requirements [\#294](https://github.com/OpenVoiceOS/ovos-utils/pull/294) ([dependabot[bot]](https://github.com/apps/dependabot)) +- move oauth utils to ovos-utils and deprecate backend-client [\#299](https://github.com/OpenVoiceOS/ovos-utils/pull/299) ([JarbasAl](https://github.com/JarbasAl)) diff --git a/ovos_utils/oauth.py b/ovos_utils/oauth.py new file mode 100644 index 0000000..300cd98 --- /dev/null +++ b/ovos_utils/oauth.py @@ -0,0 +1,70 @@ +from json_database import JsonStorageXDG +from ovos_config.locations import get_xdg_cache_save_path + + +class OAuthTokenDatabase(JsonStorageXDG): + """ This helper class creates ovos-config-assistant/ovos-backend-manager compatible json databases + This allows users to use oauth even when not using a backend""" + + def __init__(self): + super().__init__("ovos_oauth", xdg_folder=get_xdg_cache_save_path()) + + def add_token(self, token_id, token_data): + self[token_id] = token_data + + def update_token(self, token_id, token_data): + self.add_token(token_id, token_data) + + def get_token(self, token_id): + return self.get(token_id) + + def delete_token(self, token_id): + if token_id in self: + self.pop(token_id) + return True + return False + + def total_tokens(self): + return len(self) + + +class OAuthApplicationDatabase(JsonStorageXDG): + """ This helper class creates ovos-config-assistant/ovos-backend-manager compatible json databases + This allows users to use oauth even when not using a backend""" + + def __init__(self): + super().__init__("ovos_oauth_apps", xdg_folder=get_xdg_cache_save_path()) + + def add_application(self, oauth_service, + client_id, client_secret, + auth_endpoint, token_endpoint, callback_endpoint, scope, + shell_integration=True): + self[oauth_service] = {"oauth_service": oauth_service, + "client_id": client_id, + "client_secret": client_secret, + "auth_endpoint": auth_endpoint, + "token_endpoint": token_endpoint, + "callback_endpoint": callback_endpoint, + "scope": scope, + "shell_integration": shell_integration} + + def get_application(self, oauth_service): + return self.get(oauth_service) + + def update_application(self, oauth_service, + client_id, client_secret, + auth_endpoint, token_endpoint, + callback_endpoint, scope, shell_integration=True): + self.add_application(oauth_service, + client_id, client_secret, + auth_endpoint, token_endpoint, + callback_endpoint, scope, shell_integration) + + def delete_application(self, oauth_service): + if oauth_service in self: + self.pop(oauth_service) + return True + return False + + def total_apps(self): + return len(self) diff --git a/ovos_utils/version.py b/ovos_utils/version.py index 21df551..e75d037 100644 --- a/ovos_utils/version.py +++ b/ovos_utils/version.py @@ -1,6 +1,6 @@ # START_VERSION_BLOCK VERSION_MAJOR = 0 VERSION_MINOR = 4 -VERSION_BUILD = 0 -VERSION_ALPHA = 0 +VERSION_BUILD = 1 +VERSION_ALPHA = 1 # END_VERSION_BLOCK