Merge commit from fork

This commit is contained in:
Livio Spring
2025-10-29 10:12:50 +01:00
committed by GitHub
parent b8db8cdf9c
commit b284f8474e
6 changed files with 122 additions and 19 deletions
+15 -6
View File
@@ -12,6 +12,7 @@ import (
"github.com/zitadel/logging"
"github.com/zitadel/zitadel/internal/api/authz"
"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"
@@ -222,9 +223,11 @@ func (q *Queries) ListUserAuthMethodTypes(ctx context.Context, userID string, ac
}
type UserAuthMethodRequirements struct {
UserType domain.UserType
ForceMFA bool
ForceMFALocalOnly bool
UserType domain.UserType
ForceMFA bool
ForceMFALocalOnly bool
AllowedSecondFactors []domain.SecondFactorType
SetUpFactors []domain.UserAuthMethodType
}
//go:embed user_auth_method_types_required.sql
@@ -245,10 +248,14 @@ func (q *Queries) ListUserAuthMethodTypesRequired(ctx context.Context, userID st
var userType sql.NullInt32
var forceMFA sql.NullBool
var forceMFALocalOnly sql.NullBool
var allowedSecondFactors database.NumberArray[domain.SecondFactorType]
var setUpFactors database.NumberArray[domain.UserAuthMethodType]
err := row.Scan(
&userType,
&forceMFA,
&forceMFALocalOnly,
&allowedSecondFactors,
&setUpFactors,
)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
@@ -257,9 +264,11 @@ func (q *Queries) ListUserAuthMethodTypesRequired(ctx context.Context, userID st
return zerrors.ThrowInternal(err, "QUERY-Sf3rt", "Errors.Internal")
}
requirements = &UserAuthMethodRequirements{
UserType: domain.UserType(userType.Int32),
ForceMFA: forceMFA.Bool,
ForceMFALocalOnly: forceMFALocalOnly.Bool,
UserType: domain.UserType(userType.Int32),
ForceMFA: forceMFA.Bool,
ForceMFALocalOnly: forceMFALocalOnly.Bool,
AllowedSecondFactors: allowedSecondFactors,
SetUpFactors: setUpFactors,
}
return nil
},
@@ -1,17 +1,28 @@
SELECT
SELECT
projections.users14.type
, auth_methods_force_mfa.force_mfa
, auth_methods_force_mfa.force_mfa_local_only
FROM
projections.users14
LEFT JOIN
, auth_methods_force_mfa.force_mfa_local_only
, auth_methods_force_mfa.second_factors
, user_auth_methods5.auth_method_types
FROM
projections.users14
LEFT JOIN
projections.login_policies5 AS auth_methods_force_mfa
ON
auth_methods_force_mfa.instance_id = projections.users14.instance_id
AND auth_methods_force_mfa.aggregate_id = ANY(ARRAY[projections.users14.instance_id, projections.users14.resource_owner])
WHERE
LEFT JOIN LATERAL (
SELECT
ARRAY_AGG(projections.user_auth_methods5.method_type) AS auth_method_types
FROM
projections.user_auth_methods5
WHERE
projections.user_auth_methods5.user_id = projections.users14.id
AND projections.user_auth_methods5.instance_id = projections.users14.instance_id
) AS user_auth_methods5 ON TRUE
WHERE
projections.users14.id = $1
AND projections.users14.instance_id = $2
ORDER BY
auth_methods_force_mfa.is_default
ORDER BY
auth_methods_force_mfa.is_default
LIMIT 1;