Skip to content

Support generic OAuth for non-HTTP hosts - #1956

Closed
pl4nty wants to merge 1 commit into
git-ecosystem:mainfrom
pl4nty:patch-1
Closed

pl4nty wants to merge 1 commit into
git-ecosystem:mainfrom
pl4nty:patch-1

Conversation

@pl4nty

@pl4nty pl4nty commented Jun 14, 2025 •

Copy link
Copy Markdown

Non-HTTP hosts can support OAuth using absolute authorize and token endpoints, like EXO/Outlook.com SMTP. Example:

[sendemail]
smtpServer = smtp-mail.outlook.com
smtpUser = example@outlook.com
smtpEncryption = tls
smtpServerPort = 587
smtpAuth = XOAUTH2

[credential "smtp://smtp-mail.outlook.com:587"]
oauthClientId = a95fbac5-cbbb-4032-b10d-fb756c457ba1
oauthAuthorizeEndpoint = https://login.microsoftonline.com/common/oauth2/v2.0/authorize
oauthTokenEndpoint = https://login.microsoftonline.com/common/oauth2/v2.0/token
oauthScopes = offline_access https://outlook.office.com/SMTP.Send

Non-HTTP hosts can support OAuth using absolute authorize/token endpoints, like Outlook.com SMTP. Example:

```
[sendemail]
smtpServer = smtp-mail.outlook.com
smtpUser = example@outlook.com
smtpEncryption = tls
smtpServerPort = 587
smtpAuth = XOAUTH2

[credential "smtp://smtp-mail.outlook.com:587"]
oauthClientId = a95fbac5-cbbb-4032-b10d-fb756c457ba1
oauthAuthorizeEndpoint = https://login.microsoftonline.com/common/oauth2/v2.0/authorize
oauthTokenEndpoint = https://login.microsoftonline.com/common/oauth2/v2.0/token
oauthScopes = offline_access https://outlook.office.com/SMTP.Send
```
Comment thread src/shared/Core/GenericHostProvider.cs Outdated
Uri uri = input.GetRemoteUri();

// Determine the if the host supports Windows Integration Authentication (WIA) or OAuth
if (!StringComparer.OrdinalIgnoreCase.Equals(uri.Scheme, "http") &&

@pl4nty pl4nty Jun 14, 2025 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naive approach of just removing the guard, but we could check each endpoint instead (including DeviceCode if present?). They should be relative with HTTP(S) host, or absolute HTTP(S)

@pl4nty

pl4nty commented Jun 14, 2025

Copy link
Copy Markdown
Author

This might need a docs update too. I'd like to include git send-email examples for Gmail/Outlook.com, but Git Bash doesn't ship with the required Authen-SASL version 2.1800 yet.

I also had to test this change on an alternate account. My tom@tplant.com.au Outlook.com SMTP is broken on multiple clients, probably due to the grandfathered custom domain. Outlook support weren't helpful unfortunately.

@NIGLOBAL

This comment has been minimized.

@mjcheetham

Copy link
Copy Markdown
Contributor

Superseded by #2445

@mjcheetham mjcheetham closed this Sep 15, 2026
mjcheetham added a commit that referenced this pull request Sep 16, 2026
We currently do not consider either Windows Integrated or generic OAuth
authentication in the generic provider, for a non-HTTP based remote URL.

Since GCM can be called as a credential helper by Git for things such as
an SMTP server (see `git sendmail`), where the SMTP server may use OAuth
authentication, we should relax this restriction.

Note that we still require HTTP(S) remotes for Windows Integrated auth
since the probe for that requires an HTTP(S) call.

Replaces #1956

> [!TIP]
> Ignore whitespace when reviewing the diff in the
`GenericHostProvider.cs` file - we are adding a wrapping `if () { }`
block to existing code.
@pl4nty

pl4nty commented Oct 1, 2026

Copy link
Copy Markdown
Author

Thanks! Tested and this looks great, although my main account remains broken

@pl4nty
pl4nty deleted the patch-1 branch October 1, 2026 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants