Upgrading to radicale 3x

This commit is contained in:
Fabian Stamm
2020-09-28 18:17:28 +02:00
parent 4d29cfd9ba
commit b7832edd83
57 changed files with 21 additions and 9158 deletions

View File

@ -3,24 +3,37 @@ import urllib.request
import json
import hashlib
import requests
import logging
from radicale.log import logger
class Auth(BaseAuth):
def get_server(self):
return self.configuration.get("auth", "server")
def is_authenticated(self, user, password):
if user is None:
return False
def login(self, login, password):
logger.debug("Things %s %s", login, password)
# Get uid from username
if login is None or login is "":
return ""
res = requests.post(self.get_server() + "/api/login?type=username&username=" + login)
data = res.json()
if "error" in data:
return ""
user = data["uid"]
# Get salt
res1 = requests.post(self.get_server() + "/api/login?type=username&uid=" + user)
data1 = res1.json()
if "error" in data1:
return False
return ""
salt = data1["salt"].encode()
# Check password
id = self.configuration.get("auth", "client_id")
secret = self.configuration.get("auth", "client_secret")
password = hashlib.sha512(salt + password.encode()).hexdigest()
@ -29,16 +42,5 @@ class Auth(BaseAuth):
data2 = res2.json()
if "success" in data2 and data2["success"] is True:
return True
return False
def map_login_to_user(self, login):
# Get uid from username
if login is None or login is "":
return None
req_data = dict()
res = requests.post(self.get_server() + "/api/login?type=username&username=" + login)
data = res.json()
if "error" in data:
return None
return data["uid"]
return user
return ""