mirror of
https://github.com/andwati/zitadel.git
synced 2026-12-01 00:18:51 +00:00
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:
@@ -108,6 +108,12 @@ func smtpToPb(config *query.SMTP) *settings_pb.EmailProvider_Smtp {
|
|||||||
ret.Smtp.Auth = xoauth2
|
ret.Smtp.Auth = xoauth2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.XOAuth2Auth == nil && config.PlainAuth == nil {
|
||||||
|
ret.Smtp.Auth = &settings_pb.EmailProviderSMTP_None{
|
||||||
|
None: &settings_pb.SMTPNoAuth{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ret
|
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",
|
name: "plain auth must map to plain",
|
||||||
args: args{
|
args: args{
|
||||||
|
|||||||
@@ -4,13 +4,13 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
sq "github.com/Masterminds/squirrel"
|
sq "github.com/Masterminds/squirrel"
|
||||||
|
|
||||||
"github.com/zitadel/zitadel/internal/api/authz"
|
"github.com/zitadel/zitadel/internal/api/authz"
|
||||||
"github.com/zitadel/zitadel/internal/crypto"
|
"github.com/zitadel/zitadel/internal/crypto"
|
||||||
|
"github.com/zitadel/zitadel/internal/database"
|
||||||
"github.com/zitadel/zitadel/internal/domain"
|
"github.com/zitadel/zitadel/internal/domain"
|
||||||
"github.com/zitadel/zitadel/internal/query/projection"
|
"github.com/zitadel/zitadel/internal/query/projection"
|
||||||
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
"github.com/zitadel/zitadel/internal/telemetry/tracing"
|
||||||
@@ -451,7 +451,7 @@ type sqlSmtpConfig struct {
|
|||||||
xoauth2AuthClientCredentialsClientId sql.NullString
|
xoauth2AuthClientCredentialsClientId sql.NullString
|
||||||
xoauth2AuthClientClientCredentialsSecret *crypto.CryptoValue
|
xoauth2AuthClientClientCredentialsSecret *crypto.CryptoValue
|
||||||
xoauth2AuthTokenEndpoint sql.NullString
|
xoauth2AuthTokenEndpoint sql.NullString
|
||||||
xoauth2AuthScope sql.NullString
|
xoauth2AuthScope database.TextArray[string]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c sqlSmtpConfig) set(smtpConfig *SMTPConfig) {
|
func (c sqlSmtpConfig) set(smtpConfig *SMTPConfig) {
|
||||||
@@ -466,13 +466,9 @@ func (c sqlSmtpConfig) set(smtpConfig *SMTPConfig) {
|
|||||||
plainAuth = nil
|
plainAuth = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
scopes := strings.Split(c.xoauth2AuthScope.String, " ")
|
|
||||||
if len(scopes) == 1 && scopes[0] == "" {
|
|
||||||
scopes = nil
|
|
||||||
}
|
|
||||||
xoauth2Auth := &XOAuth2Auth{
|
xoauth2Auth := &XOAuth2Auth{
|
||||||
TokenEndpoint: c.xoauth2AuthTokenEndpoint.String,
|
TokenEndpoint: c.xoauth2AuthTokenEndpoint.String,
|
||||||
Scopes: scopes,
|
Scopes: []string(c.xoauth2AuthScope),
|
||||||
ClientCredentials: &XOAuthClientCredentials{
|
ClientCredentials: &XOAuthClientCredentials{
|
||||||
ClientId: c.xoauth2AuthClientCredentialsClientId.String,
|
ClientId: c.xoauth2AuthClientCredentialsClientId.String,
|
||||||
ClientSecret: c.xoauth2AuthClientClientCredentialsSecret,
|
ClientSecret: c.xoauth2AuthClientClientCredentialsSecret,
|
||||||
|
|||||||
Reference in New Issue
Block a user