35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
|
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"]
|