Skip to content

Fix compatibility problem with aliyun and netease mail as authentication source #27044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions services/auth/source/smtp/source_authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,13 @@ func (source *Source) Authenticate(ctx context.Context, user *user_model.User, u
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we ignore the erorr Code here?

return nil, errors.Join(util.ErrInvalidArgument, tperr)
}
return nil, err
}
Expand Down
Loading