Skip to content

Commit

Permalink
move oauth utils to ovos-utils and deprecate backend-client (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl authored Nov 20, 2024
1 parent 3bfcde3 commit a6d430d
Showing 1 changed file with 70 additions and 0 deletions.
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)

0 comments on commit a6d430d

Please sign in to comment.