fix: return auth none when no auth is configured for smtp + scopes in grpc response (#11554)

# Which Problems Are Solved

- When no auth was present on a smtp configuration, the `auth` field was
`nil` on the response while it should be `none`.
- Scopes were not properly retrieved from the database resulting in all
scopes being combined in one scope when retrieving the configuration.

# How the Problems Are Solved

- Set `auth` to `none` when no auth is configured
- Use `database.TextArray[string]` as type to get the scopes from the
database

# Additional Changes

# Additional Context
This commit is contained in:
Wim Van Laer
2026-02-11 11:48:41 +01:00
committed by GitHub
parent a24e3f03b9
commit e98aa10892
3 changed files with 22 additions and 7 deletions
@@ -108,6 +108,12 @@ func smtpToPb(config *query.SMTP) *settings_pb.EmailProvider_Smtp {
ret.Smtp.Auth = xoauth2
}
if config.XOAuth2Auth == nil && config.PlainAuth == nil {
ret.Smtp.Auth = &settings_pb.EmailProviderSMTP_None{
None: &settings_pb.SMTPNoAuth{},
}
}
return ret
}
@@ -407,6 +407,19 @@ func Test_smtpToPb(t *testing.T) {
},
},
},
{
name: "no auth must map to none",
args: args{
req: &query.SMTP{},
},
res: &settings_pb.EmailProvider_Smtp{
Smtp: &settings_pb.EmailProviderSMTP{
Auth: &settings_pb.EmailProviderSMTP_None{
None: &settings_pb.SMTPNoAuth{},
},
},
},
},
{
name: "plain auth must map to plain",
args: args{
+3 -7
View File
@@ -4,13 +4,13 @@ import (
"context"
"database/sql"
"errors"
"strings"
"time"
sq "github.com/Masterminds/squirrel"
"github.com/zitadel/zitadel/internal/api/authz"
"github.com/zitadel/zitadel/internal/crypto"
"github.com/zitadel/zitadel/internal/database"
"github.com/zitadel/zitadel/internal/domain"
"github.com/zitadel/zitadel/internal/query/projection"
"github.com/zitadel/zitadel/internal/telemetry/tracing"
@@ -451,7 +451,7 @@ type sqlSmtpConfig struct {
xoauth2AuthClientCredentialsClientId sql.NullString
xoauth2AuthClientClientCredentialsSecret *crypto.CryptoValue
xoauth2AuthTokenEndpoint sql.NullString
xoauth2AuthScope sql.NullString
xoauth2AuthScope database.TextArray[string]
}
func (c sqlSmtpConfig) set(smtpConfig *SMTPConfig) {
@@ -466,13 +466,9 @@ func (c sqlSmtpConfig) set(smtpConfig *SMTPConfig) {
plainAuth = nil
}
scopes := strings.Split(c.xoauth2AuthScope.String, " ")
if len(scopes) == 1 && scopes[0] == "" {
scopes = nil
}
xoauth2Auth := &XOAuth2Auth{
TokenEndpoint: c.xoauth2AuthTokenEndpoint.String,
Scopes: scopes,
Scopes: []string(c.xoauth2AuthScope),
ClientCredentials: &XOAuthClientCredentials{
ClientId: c.xoauth2AuthClientCredentialsClientId.String,
ClientSecret: c.xoauth2AuthClientClientCredentialsSecret,