public inbox for tools@linux.kernel.org
 help / color / mirror / Atom feed
* [PATCH] b4: allow using xoauth2/bearer token to authenticate to SMTP servers
@ 2026-03-06 16:20 Dmitry Torokhov
  2026-03-06 17:18 ` Konstantin Ryabitsev
  2026-03-13  2:05 ` Konstantin Ryabitsev
  0 siblings, 2 replies; 11+ messages in thread
From: Dmitry Torokhov @ 2026-03-06 16:20 UTC (permalink / raw)
  To: tools; +Cc: Dmitry Torokhov

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


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-03-13  3:12 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-06 16:20 [PATCH] b4: allow using xoauth2/bearer token to authenticate to SMTP servers Dmitry Torokhov
2026-03-06 17:18 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox