From 8ce96f1716bca832b4ee1593aa3489adc932e2e9 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Wed, 21 Dec 2022 11:01:37 -0600 Subject: smtp: remove requirement for oauthbearer token-endpoint The SMTP configuration is slightly different between oauthbearer and xoauth2. The oauthbearer requires a token-endpoint, while xoauth2 does not. The IMAP version of oauthbearer also does not require a token-endpoint. If one is specified, the token is treated as a refresh token. Modify the SMTP usage to work the same way: a token is an access token unless a token-endpoint is specified Reported-by: Cameron Samak Signed-off-by: Tim Culverhouse Acked-by: Robin Jarry --- commands/compose/send.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'commands') diff --git a/commands/compose/send.go b/commands/compose/send.go index 7306bef8..9edb168e 100644 --- a/commands/compose/send.go +++ b/commands/compose/send.go @@ -325,14 +325,13 @@ func newSaslClient(auth string, uri *url.URL) (sasl.Client, error) { OAuth2: oauth2, Enabled: true, } - if bearer.OAuth2.Endpoint.TokenURL == "" { - return nil, fmt.Errorf("No 'TokenURL' configured for this account") - } - token, err := bearer.ExchangeRefreshToken(password) - if err != nil { - return nil, err + if bearer.OAuth2.Endpoint.TokenURL != "" { + token, err := bearer.ExchangeRefreshToken(password) + if err != nil { + return nil, err + } + password = token.AccessToken } - password = token.AccessToken saslClient = sasl.NewOAuthBearerClient(&sasl.OAuthBearerOptions{ Username: uri.User.Username(), Token: password, -- cgit