2017-12-05 09:32:45 +00:00
|
|
|
from radicale.auth import BaseAuth
|
2017-12-05 19:55:18 +00:00
|
|
|
import urllib.request
|
|
|
|
import json
|
2017-12-12 09:52:17 +00:00
|
|
|
import hashlib
|
2018-09-23 10:45:39 +00:00
|
|
|
import requests
|
|
|
|
|
2017-12-05 09:32:45 +00:00
|
|
|
|
|
|
|
class Auth(BaseAuth):
|
2018-09-23 10:45:39 +00:00
|
|
|
def get_server(self):
|
|
|
|
return self.configuration.get("auth", "server")
|
2017-12-05 09:32:45 +00:00
|
|
|
|
|
|
|
def is_authenticated(self, user, password):
|
2017-12-05 19:55:18 +00:00
|
|
|
if user is None:
|
2017-12-05 09:32:45 +00:00
|
|
|
return False
|
2018-09-23 10:45:39 +00:00
|
|
|
|
|
|
|
res1 = requests.post(self.get_server + "/api/login?uid=" + user)
|
|
|
|
data1 = res1.json()
|
|
|
|
|
2017-12-05 19:55:18 +00:00
|
|
|
if "error" in data:
|
2017-12-05 09:32:45 +00:00
|
|
|
return False
|
2018-09-23 10:45:39 +00:00
|
|
|
|
|
|
|
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
|
2017-12-05 09:32:45 +00:00
|
|
|
|
2017-12-05 19:55:18 +00:00
|
|
|
def map_login_to_user(self, login):
|
2018-03-31 23:51:48 +00:00
|
|
|
# Get uid from username
|
2017-12-05 19:55:18 +00:00
|
|
|
if login is None or login is "":
|
|
|
|
return None
|
2018-09-23 10:45:39 +00:00
|
|
|
req_data=dict()
|
|
|
|
res=requests.post(self.get_server + "/api/login?username=" + login)
|
|
|
|
data=res.json()
|
2017-12-05 19:55:18 +00:00
|
|
|
if "error" in data:
|
2017-12-05 09:32:45 +00:00
|
|
|
return None
|
2018-03-31 23:51:48 +00:00
|
|
|
return data["uid"]
|