In case anyone is interested, I have filed bug#72992[1] where I posted my code to enable xoauth2 support for nnimap and smtpmail as I promised. I am also trying to gather feedback on how it can be improved. Comments welcome!
[1] https://lists.gnu.org/archive/html/bug-gnu-emacs/2024-09/msg00089.html -- Xiyue Deng