Daniel Olsen
e4625e8061
All checks were successful
Eval nix flake / evals (push) Successful in 2m56s
yolo lmao
41 lines
1.0 KiB
Python
41 lines
1.0 KiB
Python
from typing import Awaitable, Callable, Optional, Tuple
|
|
|
|
from smtplib import SMTP_SSL as SMTP
|
|
|
|
import synapse
|
|
from synapse import module_api
|
|
|
|
|
|
class SMTPAuthProvider:
|
|
def __init__(self, config: dict, api: module_api):
|
|
self.api = api
|
|
|
|
api.register_password_auth_provider_callbacks(
|
|
auth_checkers={
|
|
("m.login.password", ("password",)): self.check_pass,
|
|
},
|
|
)
|
|
|
|
async def check_pass(
|
|
self,
|
|
username: str,
|
|
login_type: str,
|
|
login_dict: "synapse.module_api.JsonDict",
|
|
):
|
|
if login_type != "m.login.password":
|
|
return None
|
|
|
|
result = False
|
|
with SMTP(config.smtp_host) as smtp:
|
|
password = login_dict.get("password")
|
|
try:
|
|
smtp.login(username, password)
|
|
except:
|
|
return None
|
|
result = True
|
|
|
|
if result == True:
|
|
return (self.api.get_qualified_user_id(username), None)
|
|
else:
|
|
return None
|