Skip to content

Commit 13a2383

Browse files
committed
Show error instead of 500 HTTP error if authenticate fails via external SMTP
Close #27043
1 parent f35850f commit 13a2383

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

services/auth/source/smtp/source_authenticate.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,13 @@ func (source *Source) Authenticate(ctx context.Context, user *user_model.User, u
4242
}
4343

4444
if err := Authenticate(auth, source); err != nil {
45-
// Check standard error format first,
46-
// then fallback to worse case.
47-
tperr, ok := err.(*textproto.Error)
48-
if (ok && tperr.Code == 535) ||
49-
strings.Contains(err.Error(), "Username and Password not accepted") {
50-
return nil, user_model.ErrUserNotExist{Name: userName}
51-
}
52-
if (ok && tperr.Code == 534) ||
53-
strings.Contains(err.Error(), "Application-specific password required") {
54-
return nil, user_model.ErrUserNotExist{Name: userName}
45+
// when authentication via smtp fails, wraps ErrInvalidArgument
46+
// with the original textproto.Error as the cause,
47+
// so it will show username_password_incorrect to the user
48+
// while log the original error so that admin can check.
49+
// see: routers/web/auth/auth.go SiginPost
50+
if tperr, ok := err.(*textproto.Error); ok {
51+
return nil, errors.Join(util.ErrInvalidArgument, tperr)
5552
}
5653
return nil, err
5754
}

0 commit comments

Comments
 (0)