radicale_plugins/radicale_stamm_auth/__init__.py

35 lines
1.2 KiB
Python
Raw Normal View History

2017-12-05 09:32:45 +00:00
from radicale.auth import BaseAuth
import urllib
class Auth(BaseAuth):
def _generateBaseUri(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 is_authenticated(self, user, password):
if user == None
return False
main_uri = self._generateBaseUri(
"/client/check_pw") + "&uuid=" + user + "&password=" + password
req = urllib.request.urlopen(main_uri, data=None)
jsons = req.read()
data = json.loads(jsons)
print(data["username"], data["uuid"])
if data["error"]
return False
return True
def map_login_to_user(self, login)
# Get uuid from username
main_uri = self._generateBaseUri("/client/uuid") + "&username=" + login
req = urllib.request.urlopen(main_uri, data=None)
jsons = req.read()
data = json.loads(jsons)
print(data["error"], data["username"], data["uuid"])
if data["error"] != None
return None
return data["uuid"]