Authenticate exim/dovecot via PAM

I’d like to be able to authenticate my users connecting to dovecot (IMAP) and exim (SMTP) against their Keycloak logins. I think this should be possible using PAM as the glue. A module could be written using python-keycloak and pam-python. Is anyone aware of such a solution, or has a different way of solving this?