Adding not tested support for openauth

This commit is contained in:
Fabian Stamm 2018-09-23 12:45:39 +02:00
parent e68646c235
commit 8ba70e7533
2 changed files with 25 additions and 19 deletions

View File

@ -2,37 +2,43 @@ from radicale.auth import BaseAuth
import urllib.request
import json
import hashlib
import requests
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 get_server(self):
return self.configuration.get("auth", "server")
def is_authenticated(self, user, password):
if user is None:
return False
main_uri = self.generate_base_uri(
"/client/check_pw") + "&hashed=true&uuid=" + user + "&password=" + hashlib.sha512(password.encode()).hexdigest()
req = urllib.request.urlopen(main_uri, data=None)
jsons = req.read()
data = json.loads(jsons)
print(data)
res1 = requests.post(self.get_server + "/api/login?uid=" + user)
data1 = res1.json()
if "error" in data:
return False
salt = data["salt"]
id = self.configuration.get("auth", "client_id")
secret = self.configuration.get("auth", "client_secret")
password = hashlib.sha512(salt + password.encode()).hexdigest())
res2=requests.post("/api/internel/password", params = {
"client_id": id, "client_secret": secret}, json = {"uid": user, "password": password})
data2=res2.json();
if "success" in data2 and data["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
main_uri = self.generate_base_uri(
"/client/uid") + "&username=" + login
req = urllib.request.urlopen(main_uri, data=None)
jsons = req.read()
data = json.loads(jsons)
print(data)
req_data=dict()
res=requests.post(self.get_server + "/api/login?username=" + login)
data=res.json()
if "error" in data:
return None
return data["uid"]

View File

@ -2,6 +2,6 @@
from distutils.core import setup
setup(name="radicale_stamm_auth", packages=["radicale_stamm_auth"])
setup(name="radicale_openauth", packages=["radicale_stamm_auth"])
setup(name="radicale_stamm_rights", packages=["radicale_stamm_rights"])