1
0
forked from baron/baron-sso

Merge pull request 'feature/issue-917-sub-email-support' (#931) from feature/issue-917-sub-email-support into dev

Reviewed-on: baron/baron-sso#931
This commit is contained in:
2026-05-29 13:14:11 +09:00
10 changed files with 409 additions and 44 deletions

View File

@@ -374,7 +374,7 @@ func (h *AuthHandler) CheckLoginID(c *fiber.Ctx) error {
}
// Basic validation via our ValidateLoginID helper (without email/phone since we just check format & collision with reserved words)
if err := domain.ValidateLoginID(req.LoginID, "", ""); err != nil {
if err := domain.ValidateLoginID(req.LoginID, []string{}, ""); err != nil {
return c.JSON(fiber.Map{"available": false, "message": err.Error()})
}
@@ -801,7 +801,7 @@ func (h *AuthHandler) Signup(c *fiber.Ctx) error {
// Validate all collected LoginIDs
if collectedIDs, ok := attributes["custom_login_ids"].([]string); ok {
for _, lid := range collectedIDs {
if err := domain.ValidateLoginID(lid, req.Email, normalizedPhone); err != nil {
if err := domain.ValidateLoginID(lid, []string{req.Email}, normalizedPhone); err != nil {
return errorJSON(c, fiber.StatusBadRequest, "Invalid LoginID ("+lid+"): "+err.Error())
}
}
@@ -1769,7 +1769,7 @@ func collectEmailList(traits map[string]any, primaryEmail string) []string {
}
}
if raw, ok := traits["secondary_emails"]; ok {
if raw, ok := traits["sub_email"]; ok {
switch value := raw.(type) {
case []string:
for _, email := range value {
@@ -7953,7 +7953,7 @@ func (h *AuthHandler) UpdateMe(c *fiber.Ctx) error {
userPhone := extractTraitString(traits, "phone_number")
if collectedIDs, ok := traits["custom_login_ids"].([]string); ok {
for _, lid := range collectedIDs {
if err := domain.ValidateLoginID(lid, userEmail, userPhone); err != nil {
if err := domain.ValidateLoginID(lid, []string{userEmail}, userPhone); err != nil {
return errorJSON(c, fiber.StatusBadRequest, "Invalid LoginID ("+lid+"): "+err.Error())
}
}

View File

@@ -757,7 +757,7 @@ func (h *UserHandler) CreateUser(c *fiber.Ctx) error {
// Validate all collected LoginIDs
if collectedIDs, ok := attributes["custom_login_ids"].([]string); ok {
for _, lid := range collectedIDs {
if err := domain.ValidateLoginID(lid, email, normalizePhoneNumber(req.Phone)); err != nil {
if err := domain.ValidateLoginID(lid, []string{email}, normalizePhoneNumber(req.Phone)); err != nil {
return errorJSON(c, fiber.StatusBadRequest, "Invalid LoginID ("+lid+"): "+err.Error())
}
}
@@ -1224,8 +1224,22 @@ func (h *UserHandler) BulkCreateUsers(c *fiber.Ctx) error {
// Validate all collected LoginIDs
if collectedIDs, ok := attributes["custom_login_ids"].([]string); ok {
valid := true
// Collect all emails
allEmails := []string{userEmail}
if secondaryRaw, exists := item.Metadata["sub_email"]; exists {
if secondaryEmails, ok := secondaryRaw.([]interface{}); ok {
for _, se := range secondaryEmails {
if seStr, ok := se.(string); ok {
allEmails = append(allEmails, seStr)
}
}
} else if secondaryEmails, ok := secondaryRaw.([]string); ok {
allEmails = append(allEmails, secondaryEmails...)
}
}
for _, lid := range collectedIDs {
if err := domain.ValidateLoginID(lid, userEmail, userPhone); err != nil {
if err := domain.ValidateLoginID(lid, allEmails, userPhone); err != nil {
results = append(results, bulkUserResult{Email: userEmail, OriginalEmail: emailEvaluation.OriginalEmail, SuggestedEmail: emailEvaluation.SuggestedEmail, Status: emailEvaluation.Status, Warnings: emailEvaluation.Warnings, Success: false, Message: "Invalid LoginID (" + lid + "): " + err.Error()})
valid = false
break
@@ -2036,9 +2050,23 @@ func (h *UserHandler) UpdateUser(c *fiber.Ctx) error {
// Validate all collected LoginIDs
userEmail := extractTraitString(traits, "email")
userPhone := extractTraitString(traits, "phone_number")
allEmails := []string{userEmail}
if secondaryRaw, exists := traits["sub_email"]; exists {
if secondaryEmails, ok := secondaryRaw.([]interface{}); ok {
for _, se := range secondaryEmails {
if seStr, ok := se.(string); ok {
allEmails = append(allEmails, seStr)
}
}
} else if secondaryEmails, ok := secondaryRaw.([]string); ok {
allEmails = append(allEmails, secondaryEmails...)
}
}
if collectedIDs, ok := traits["custom_login_ids"].([]string); ok {
for _, lid := range collectedIDs {
if err := domain.ValidateLoginID(lid, userEmail, userPhone); err != nil {
if err := domain.ValidateLoginID(lid, allEmails, userPhone); err != nil {
return errorJSON(c, fiber.StatusBadRequest, "Invalid LoginID ("+lid+"): "+err.Error())
}
}