fix cannot create success login (#2576)

Signed-off-by: Jeff <zw0948@gmail.com>
This commit is contained in:
zryfish
2020-07-24 13:09:38 +08:00
committed by GitHub
parent 06932926a0
commit f1146f5d6c
23 changed files with 2183 additions and 271 deletions

View File

@@ -133,7 +133,7 @@ func (h *handler) Authorize(req *restful.Request, resp *restful.Response) {
http.Redirect(resp, req.Request, redirectURL, http.StatusFound)
}
func (h *handler) OAuthCallBack(req *restful.Request, resp *restful.Response) {
func (h *handler) oAuthCallBack(req *restful.Request, resp *restful.Response) {
code := req.QueryParameter("code")
name := req.PathParameter("callback")
@@ -161,7 +161,7 @@ func (h *handler) OAuthCallBack(req *restful.Request, resp *restful.Response) {
identity, err := oauthIdentityProvider.IdentityExchange(code)
if err != nil {
err := apierrors.NewUnauthorized(fmt.Sprintf("Unauthorized: %s", err))
err = apierrors.NewUnauthorized(fmt.Sprintf("Unauthorized: %s", err))
resp.WriteError(http.StatusUnauthorized, err)
return
}
@@ -217,7 +217,7 @@ func (h *handler) OAuthCallBack(req *restful.Request, resp *restful.Response) {
return
}
if err = h.loginRecorder.RecordLogin(authenticated.Name, nil, req.Request); err != nil {
if err = h.loginRecorder.RecordLogin(authenticated.Name, iamv1alpha2.OAuth, providerOptions.Name, nil, req.Request); err != nil {
klog.Error(err)
err := apierrors.NewInternalError(err)
resp.WriteError(http.StatusInternalServerError, err)
@@ -273,9 +273,9 @@ func (h *handler) passwordGrant(username string, password string, req *restful.R
authenticated, err := h.authenticator.Authenticate(username, password)
if err != nil {
if err == im.AuthFailedIncorrectPassword {
if err := h.loginRecorder.RecordLogin(username, err, req.Request); err != nil {
if err := h.loginRecorder.RecordLogin(username, iamv1alpha2.Token, "", err, req.Request); err != nil {
klog.Error(err)
err := apierrors.NewInternalError(err)
err = apierrors.NewInternalError(err)
response.WriteError(http.StatusInternalServerError, err)
return
}
@@ -284,7 +284,7 @@ func (h *handler) passwordGrant(username string, password string, req *restful.R
err == im.AuthFailedIdentityMappingNotMatch ||
err == im.AuthRateLimitExceeded {
klog.V(4).Info(err)
err := apierrors.NewUnauthorized(fmt.Sprintf("Unauthorized: %s", err))
err = apierrors.NewUnauthorized(fmt.Sprintf("Unauthorized: %s", err))
response.WriteError(http.StatusUnauthorized, err)
return
}
@@ -302,7 +302,7 @@ func (h *handler) passwordGrant(username string, password string, req *restful.R
return
}
if err = h.loginRecorder.RecordLogin(authenticated.GetName(), nil, req.Request); err != nil {
if err = h.loginRecorder.RecordLogin(authenticated.GetName(), iamv1alpha2.Token, "", nil, req.Request); err != nil {
klog.Error(err)
err := apierrors.NewInternalError(err)
response.WriteError(http.StatusInternalServerError, err)

View File

@@ -91,7 +91,7 @@ func AddToContainer(c *restful.Container, im im.IdentityManagementInterface, tok
"otherwise, REQUIRED. The scope of the access token as described by [RFC6479] Section 3.3.").Required(false)).
Param(ws.QueryParameter("state", "if the \"state\" parameter was present in the client authorization request."+
"The exact value received from the client.").Required(true)).
To(handler.OAuthCallBack).
To(handler.oAuthCallBack).
Returns(http.StatusOK, api.StatusOK, oauth.Token{}))
c.Add(ws)