-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
modify api authentication failed message #27842
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: leon <leondevlifelog@gmail.com>
@@ -18,7 +20,8 @@ type AuthResult struct { | |||
func AuthShared(ctx *context.Base, sessionStore auth_service.SessionStore, authMethod auth_service.Method) (ar AuthResult, err error) { | |||
ar.Doer, err = authMethod.Verify(ctx.Req, ctx.Resp, ctx, sessionStore) | |||
if err != nil { | |||
return ar, err | |||
log.Warn("authentication failed", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we need to detect the errors type to decide whether error we should return.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It means to only return ErrBadAccessToken for authentication related errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Verify
method returns various kinds of errors because it includes various auth methods. However, detecting the error type is also a tough task. I can recall there is a bugfix PR trying to fix 500
after deleting a user with the wrong password. But the PR is stuck because it can't cover error types for all cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lunny @lng2020
Maybe this func (userIDFromToken
) could return type int64,error
, by modifying the return type, the error type can be returned correctly.
Lines 139 to 143 in a18ecae
id := o.userIDFromToken(req.Context(), token, store) | |
if id <= 0 && id != -2 { // -2 means actions, so we need to allow it. | |
return nil, user_model.ErrUserNotExist{} | |
} |
If you approve i will close this PR and open another one.
close #27695