-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Remove modules/context
from SSPI
#27027
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
base: main
Are you sure you want to change the base?
Conversation
Related #27027 Extract the router logic from `services/auth/middleware.go` into `routers/web` <-> `routers/common` <-> `routers/api`.
I think the original code is also broken: The SSPI auth is only active on if !s.shouldAuthenticate(req) {
return nil, nil
} The first request always results in an expected error because no userInfo, outToken, err := sspiAuth.Authenticate(req, w)
if err != nil { Now the sspiAuth.AppendAuthenticateHeader(w, outToken)
// Include the user login page in the 401 response to allow the user
// to login with another authentication method if SSPI authentication
// fails
store.GetData()["Flash"] = map[string]string{
"ErrorMsg": err.Error(),
}
store.GetData()["EnableOpenIDSignIn"] = setting.Service.EnableOpenIDSignIn
store.GetData()["EnableSSPI"] = true
// in this case, the Verify function is called in Gitea's web context
// FIXME: it doesn't look good to render the page here, why not redirect?
gitea_context.GetWebContext(req).HTML(http.StatusUnauthorized, tplSignIn)
|
Actually it does work (for web users): SSPI auth error after update to 1.20.0 #25952 But for API ... no idea. I guess few people really need it, and I do not have enough understanding nor have the test env for it. |
What do you think about a new interface sample code: func Auth(ctx *context.Base, method Method, challengeRespondMethod ChallengeRespondMethod) (*user_model.User, error) {
user, err := method.Verify(ctx.Req)
if err != nil {
return nil, err
}
if user != nil {
return user, nil
}
result, err := challengeRespondMethod.Verify(ctx.Req, ctx.Resp)
if err != nil {
return nil, err
}
if result.User != nil {
return result.User, nil
}
// only in web context
if result.RedirectToLogin {
ctx.Redirect(...)
}
return nil, nil
} |
Instead introducing more interfaces, could the user, responder, err := method.Verify(ctx.Req)
if err != nil {
return ..., err
}
if responder != nil {
responder.WriteTo(ctx.Resp)
} ps: what do you think about Make SSPI auth mockable #27036 ? |
Since #27036 merged, this can be rebased. |
Related #27028
Extracted from another PR I'm working on.
This PR removes the dependency of
modules/context
from SSPI.SSPI does not work nicely with our current auth design because it needs a specific workflow (request-response challenge). The old code renders a (bugged version) of the login page and needs
modules/context
to do that.The new code renders the login page now for every failed auth method and shows a generic error to hide possible secrets in the message. This happens only if the error occured on the login page. For all other routes the old behaviour is active. SSPI needs a 401 Unauthorized response code. This can't be set in the auth handler because
ctx.Written
blocks the processing of other handlers. Therefore the login page now renders with the 401 status code. For a normal web browser user this is not noticeable.