Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move oauth utils to ovos-utils and deprecate backend-client #299

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions ovos_utils/oauth.py
Original file line number Diff line number Diff line change
@@ -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)
Loading