Subject: Re: bug#78366: 30.1; auth-source-xoauth2-plugin conflicts with multiple Google accounts

From: Robert Pluim <[email-masked]>
Date: Thu, 15 May 2025 11:42:42 +0200

>>>>> On Thu, 15 May 2025 00:17:02 -0700, Xiyue Deng <[email-masked]> said:

    Xiyue> Thanks for the insights! I managed to reproduce the issue, and during
    Xiyue> debugging I got the list from the reply as Anush mentioned.  Turned out
    Xiyue> that the return code was 334 server challenge[1], so it was waiting for
    Xiyue> the correct user and password.  Sometimes this was directly considered
    Xiyue> authentication unsuccessful for Gmail[2].  `smtpmail-ok-p' considers a
    Xiyue> return code less than 400 as successful, and only has challenge handling
    Xiyue> implemented in cram-md5.  As we should be providing the correct
    Xiyue> credentials directly in xoauth2, 334 is effectively a failure.

    Xiyue> Maybe in `smtpmail-try-auth-method' for xoauth2, if we see return code
    Xiyue> 334, we should change the return value to "535 5.7.8 Authentication
    Xiyue> credentials invalid".  Would like to see whether the Emacs maintainers
    Xiyue> this is a good idea.

Itʼs either that, or change `smtpmail-ok-p' to accept a second
optional parameter for which codes to accept for success, which seems
like overkill here.

Iʼm confused as to why Gmail is returning 334 here, if as you say the
credentials should be correct. Would answering the challenge help?

    Xiyue> Meanwhile, a workaround for auth-source-xoauth2-plugin is to put xoauth2
    Xiyue> as the last entry in `smtpmail-auth-supported'.  Anush, can you try
    Xiyue> enable auth-source-xoauth2-plugin and eval `(setq smtp-auth-supported
    Xiyue> '(cram-md5 plain login xoauth2))' and see if this helps?

If this fixes the issue, you could put this workaround in your xoauth2
package.

Robert
--