bicep/matrix: enable smtp auth
All checks were successful
Eval nix flake / evals (push) Successful in 3m29s

yolo lmao
This commit is contained in:
Daniel Lovbrotte Olsen 2023-10-22 01:10:03 +02:00
parent a6196e67fe
commit 1e6d8ea264
4 changed files with 80 additions and 0 deletions

View File

@ -0,0 +1,17 @@
{ lib, buildPythonPackage, fetchFromGitHub }:
buildPythonPackage rec {
pname = "matrix-synapse-smtp-auth";
version = "0.1.0";
src = ./.;
doCheck = false;
meta = with lib; {
description = "An SMTP auth provider for Synapse";
homepage = "pvv.ntnu.no";
license = licenses.agpl3Only;
maintainers = with maintainers; [ dandellion ];
};
}

View File

@ -0,0 +1,11 @@
from setuptools import setup
setup(
name="matrix-synapse-smtp-auth",
version="0.1.0",
py_modules=['smtp_auth_provider'],
author="Daniel Løvbrøtte Olsen",
author_email="danio@pvv.ntnu.no",
description="An SMTP auth provider for Synapse",
license="AGPL-3.0-only"
)

View File

@ -0,0 +1,40 @@
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

View File

@ -25,6 +25,10 @@ in {
services.matrix-synapse-next = { services.matrix-synapse-next = {
enable = true; enable = true;
plugins = [
(pkgs.python3Packages.callPackage ./smtp-authenticator { })
];
dataDir = "/data/synapse"; dataDir = "/data/synapse";
workers.federationSenders = 2; workers.federationSenders = 2;
@ -83,6 +87,14 @@ in {
password_config.enabled = lib.mkForce false; password_config.enabled = lib.mkForce false;
modules = [
{ module = "smtp_auth_provider.SMTPAuthProvider";
config = {
smtp_host = "smtp.pvv.ntnu.no";
};
}
];
trusted_key_servers = [ trusted_key_servers = [
{ server_name = "matrix.org"; } { server_name = "matrix.org"; }
{ server_name = "dodsorf.as"; } { server_name = "dodsorf.as"; }