from radicale.auth import BaseAuth import urllib.request import json class Auth(BaseAuth): def generate_base_uri(self, endpoint): server = self.configuration.get("auth", "server") id = self.configuration.get("auth", "client_id") secret = self.configuration.get("auth", "client_secret") return "{}{}?client_id={}&client_secret={}".format(server, endpoint, id, secret) def is_authenticated(self, user, password): if user is None: return False main_uri = self.generate_base_uri( "/client/check_pw") + "&uuid=" + user + "&password=" + password req = urllib.request.urlopen(main_uri, data=None) jsons = req.read() data = json.loads(jsons) print(data) if "error" in data: return False return True def map_login_to_user(self, login): # Get uuid from username if login is None or login is "": return None main_uri = self.generate_base_uri( "/client/uuid") + "&username=" + login req = urllib.request.urlopen(main_uri, data=None) jsons = req.read() data = json.loads(jsons) print(data) if "error" in data: return None return data["uuid"]