public inbox for tools@linux.kernel.org
 help / color / mirror / Atom feed
From: Tomas Melin <tomas.melin@vaisala.com>
To: "Kernel.org Tools" <tools@kernel.org>
Cc: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Subject: Re: [PATCH b4 2/2] b4: add support for oauth2 SMTP authentication
Date: Fri, 30 Jan 2026 14:09:55 +0200	[thread overview]
Message-ID: <8c95aeb9-d366-4d83-80aa-a0a60c2fed73@vaisala.com> (raw)
In-Reply-To: <20260129-smtp-oauth2-outlook-v1-2-e8c6d1b00c03@vaisala.com>

Hi,

On 29/01/2026 11:10, Tomas Melin wrote:

> 
> diff --git a/src/b4/__init__.py b/src/b4/__init__.py
> index 3d774f70c026..0adf5ca4e435 100644
> --- a/src/b4/__init__.py
> +++ b/src/b4/__init__.py
> @@ -30,6 +30,7 @@ import shutil
>  import mailbox
>  import pwd
>  import io
> +import base64
>  
>  import requests
>  
> @@ -2922,6 +2923,16 @@ def git_credential_fill(gitdir: Optional[str], protocol: str, host: str, usernam
>      return None
>  
>  
> +def git_credential_helper(name: str) -> str:
> +    if not name:
> +        raise ValueError("credential helper name cannot be empty")
> +    name = 'credential-' + name
> +    ecode, out = git_run_command(None, args=[name])
> +    if ecode == 0:
> +        return out.strip()
> +    return ''

For V2 I will expand this function to work for general case with custom
command syntax, as is the case with git credentials.
(https://git-scm.com/docs/gitcredentials)

Before preparing V2 I would also appreciate any other feedback.

Thanks,
Tomas



> +
> +
>  def git_get_command_lines(gitdir: Optional[str], args: List[str]) -> List[str]:
>      ecode, out = git_run_command(gitdir, args)
>      lines = list()
> @@ -4050,6 +4061,15 @@ def get_sendemail_config() -> Dict[str, Optional[Union[str, List[str]]]]:
>      return SENDEMAIL_CONFIG
>  
>  
> +def get_oauth2_token(server: str, smtpuser: str) -> str:
> +    creds = get_config_from_git(rf'credential.*{server}*')
> +    access_token = git_credential_helper(creds.get('helper', ''))
> +    if not access_token:
> +        raise smtplib.SMTPException(f'Unable to get access token from git credential helper for server {server}')
> +    auth_string = f'user={smtpuser}\x01auth=Bearer {access_token}\x01\x01'
> +    return base64.b64encode(auth_string.encode()).decode()
> +
> +
>  def get_smtp(dryrun: bool = False) -> Tuple[Union[smtplib.SMTP, smtplib.SMTP_SSL, List[str], None], str]:
>      sconfig = get_sendemail_config()
>      # Limited support for smtp settings to begin with, but should cover the vast majority of cases
> @@ -4118,6 +4138,11 @@ def get_smtp(dryrun: bool = False) -> Tuple[Union[smtplib.SMTP, smtplib.SMTP_SSL
>          if smtpauth.lower() == 'none':
>              return smtp, fromaddr
>  
> +        if (sconfig.get('smtpauth').lower() == 'xoauth2'):
> +            logger.debug('Authenticating to SMTP server using oauth2')
> +            auth_b64 = get_oauth2_token(server, sconfig.get('smtpuser'))
> +            smtp.docmd('AUTH', 'XOAUTH2 ' + auth_b64)
> +
>          auser = str(sconfig.get('smtpuser', ''))
>          apass = str(sconfig.get('smtppass', ''))
>          if auser and not apass:
> 


  reply	other threads:[~2026-01-30 12:10 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-29  9:10 [PATCH b4 0/2] Add support for oauth2 SMTP authentication Tomas Melin
2026-01-29  9:10 ` [PATCH b4 1/2] ez: add SMTP authentication method to printed information Tomas Melin
2026-02-01  5:37   ` Konstantin Ryabitsev
2026-02-02 14:31     ` Tomas Melin
2026-01-29  9:10 ` [PATCH b4 2/2] b4: add support for oauth2 SMTP authentication Tomas Melin
2026-01-30 12:09   ` Tomas Melin [this message]
2026-02-01  5:37   ` Konstantin Ryabitsev
2026-02-02 14:08     ` Tomas Melin
2026-02-02 16:49     ` Tomas Melin
2026-02-03  3:31       ` Konstantin Ryabitsev
2026-02-01  5:37 ` [PATCH b4 0/2] Add " Konstantin Ryabitsev
2026-02-01  5:52   ` Konstantin Ryabitsev
2026-02-05  9:18     ` Tomas Melin

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=8c95aeb9-d366-4d83-80aa-a0a60c2fed73@vaisala.com \
    --to=tomas.melin@vaisala.com \
    --cc=konstantin@linuxfoundation.org \
    --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