Fixing wrong names
This commit is contained in:
44
plugins/radicale_openauth/__init__.py
Normal file
44
plugins/radicale_openauth/__init__.py
Normal file
@ -0,0 +1,44 @@
|
||||
from radicale.auth import BaseAuth
|
||||
import urllib.request
|
||||
import json
|
||||
import hashlib
|
||||
import requests
|
||||
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
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"]
|
Reference in New Issue
Block a user