Adding not tested support for openauth
This commit is contained in:
parent
e68646c235
commit
8ba70e7533
@ -2,37 +2,43 @@ from radicale.auth import BaseAuth
|
|||||||
import urllib.request
|
import urllib.request
|
||||||
import json
|
import json
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
class Auth(BaseAuth):
|
class Auth(BaseAuth):
|
||||||
def generate_base_uri(self, endpoint):
|
def get_server(self):
|
||||||
server = self.configuration.get("auth", "server")
|
return 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):
|
def is_authenticated(self, user, password):
|
||||||
if user is None:
|
if user is None:
|
||||||
return False
|
return False
|
||||||
main_uri = self.generate_base_uri(
|
|
||||||
"/client/check_pw") + "&hashed=true&uuid=" + user + "&password=" + hashlib.sha512(password.encode()).hexdigest()
|
res1 = requests.post(self.get_server + "/api/login?uid=" + user)
|
||||||
req = urllib.request.urlopen(main_uri, data=None)
|
data1 = res1.json()
|
||||||
jsons = req.read()
|
|
||||||
data = json.loads(jsons)
|
|
||||||
print(data)
|
|
||||||
if "error" in data:
|
if "error" in data:
|
||||||
return False
|
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 True
|
||||||
|
return False
|
||||||
|
|
||||||
def map_login_to_user(self, login):
|
def map_login_to_user(self, login):
|
||||||
# Get uid from username
|
# Get uid from username
|
||||||
if login is None or login is "":
|
if login is None or login is "":
|
||||||
return None
|
return None
|
||||||
main_uri = self.generate_base_uri(
|
req_data=dict()
|
||||||
"/client/uid") + "&username=" + login
|
res=requests.post(self.get_server + "/api/login?username=" + login)
|
||||||
req = urllib.request.urlopen(main_uri, data=None)
|
data=res.json()
|
||||||
jsons = req.read()
|
|
||||||
data = json.loads(jsons)
|
|
||||||
print(data)
|
|
||||||
if "error" in data:
|
if "error" in data:
|
||||||
return None
|
return None
|
||||||
return data["uid"]
|
return data["uid"]
|
||||||
|
@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
from distutils.core import setup
|
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"])
|
setup(name="radicale_stamm_rights", packages=["radicale_stamm_rights"])
|
||||||
|
Loading…
Reference in New Issue
Block a user