From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: tools@kernel.org
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Subject: [PATCH] b4: allow using xoauth2/bearer token to authenticate to SMTP servers
Date: Fri, 6 Mar 2026 08:20:18 -0800 [thread overview]
Message-ID: <20260306162020.54683-1-dtor@chromium.org> (raw)
Allow using XOAUTH2 as an authentication protocol and assume that when
XOAUTH2 is specified the password is actually a bearer token (typically
not stored in the config but rather returned via "git credentials".
Recognize "oauth", "oauth2" as aliases for "xoauth2".
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
src/b4/__init__.py | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/src/b4/__init__.py b/src/b4/__init__.py
index eab290b..9a5d25b 100644
--- a/src/b4/__init__.py
+++ b/src/b4/__init__.py
@@ -4312,8 +4312,8 @@ def get_smtp(dryrun: bool = False) -> Tuple[Union[smtplib.SMTP, smtplib.SMTP_SSL
# If we got to this point, we should do authentication,
# unless smtpauth is set to a special "none" value
- smtpauth = str(sconfig.get('smtpauth', ''))
- if smtpauth.lower() == 'none':
+ smtpauth = str(sconfig.get('smtpauth', '')).lower()
+ if smtpauth == 'none':
return smtp, fromaddr
auser = str(sconfig.get('smtpuser', ''))
@@ -4331,7 +4331,11 @@ def get_smtp(dryrun: bool = False) -> Tuple[Union[smtplib.SMTP, smtplib.SMTP_SSL
raise smtplib.SMTPException('No password specified for connecting to %s', server)
if auser and apass:
# Let any exceptions bubble up
- smtp.login(auser, apass)
+ if smtpauth in ('oauth', 'oauth2', 'xoauth2'):
+ auth_str = f'user={auser}\x01auth=Bearer {apass}\x01\x01'
+ smtp.auth('XOAUTH2', lambda: auth_str)
+ else:
+ smtp.login(auser, apass)
else:
# We assume you know what you're doing if you don't need encryption
smtp = smtplib.SMTP(server, port)
--
2.53.0.473.g4a7958ca14-goog
next reply other threads:[~2026-03-06 16:20 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-06 16:20 Dmitry Torokhov [this message]
2026-03-06 17:18 ` [PATCH] b4: allow using xoauth2/bearer token to authenticate to SMTP servers Konstantin Ryabitsev
2026-03-06 17:35 ` Dmitry Torokhov
2026-03-09 7:28 ` Tomas Melin
2026-03-09 7:49 ` Dmitry Torokhov
2026-03-09 9:50 ` Tomas Melin
2026-03-09 17:13 ` Dmitry Torokhov
2026-03-10 6:48 ` Tomas Melin
2026-03-10 7:10 ` Dmitry Torokhov
2026-03-11 15:41 ` Konstantin Ryabitsev
2026-03-13 2:05 ` Konstantin Ryabitsev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260306162020.54683-1-dtor@chromium.org \
--to=dmitry.torokhov@gmail.com \
--cc=tools@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox