mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
AuthToken: client token rotation fix (#65709)
* AuthToken: respond with 401 if token is not found * Set retry to one so we don't retry a failed token rotation
This commit is contained in:
parent
355f47628f
commit
46cfb73e21
@ -86,7 +86,7 @@ func (hs *HTTPServer) RotateUserAuthToken(c *contextmodel.ReqContext) response.R
|
|||||||
}
|
}
|
||||||
|
|
||||||
if errors.Is(err, auth.ErrUserTokenNotFound) {
|
if errors.Is(err, auth.ErrUserTokenNotFound) {
|
||||||
return response.ErrOrFallback(http.StatusNotFound, http.StatusText(http.StatusFound), err)
|
return response.ErrOrFallback(http.StatusUnauthorized, http.StatusText(http.StatusUnauthorized), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.ErrOrFallback(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError), err)
|
return response.ErrOrFallback(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError), err)
|
||||||
@ -234,7 +234,7 @@ func (hs *HTTPServer) revokeUserAuthTokenInternal(c *contextmodel.ReqContext, us
|
|||||||
return response.Error(400, "Cannot revoke active user auth token", nil)
|
return response.Error(400, "Cannot revoke active user auth token", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = hs.AuthTokenService.RevokeToken(c.Req.Context(), token, true)
|
err = hs.AuthTokenService.RevokeToken(c.Req.Context(), token, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, auth.ErrUserTokenNotFound) {
|
if errors.Is(err, auth.ErrUserTokenNotFound) {
|
||||||
return response.Error(404, "User auth token not found", err)
|
return response.Error(404, "User auth token not found", err)
|
||||||
|
@ -171,10 +171,10 @@ func TestHTTPServer_RotateUserAuthToken(t *testing.T) {
|
|||||||
expectedStatus: http.StatusUnauthorized,
|
expectedStatus: http.StatusUnauthorized,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Should return 404 and when token s not found",
|
desc: "Should return 401 and when token not found",
|
||||||
cookie: &http.Cookie{Name: "grafana_session", Value: "123", Path: "/"},
|
cookie: &http.Cookie{Name: "grafana_session", Value: "123", Path: "/"},
|
||||||
rotatedErr: auth.ErrUserTokenNotFound,
|
rotatedErr: auth.ErrUserTokenNotFound,
|
||||||
expectedStatus: http.StatusNotFound,
|
expectedStatus: http.StatusUnauthorized,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Should return 200 and but not set new cookie if token was not rotated",
|
desc: "Should return 200 and but not set new cookie if token was not rotated",
|
||||||
|
@ -450,7 +450,7 @@ export class BackendSrv implements BackendService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rotateToken() {
|
rotateToken() {
|
||||||
return this.request({ url: '/api/user/auth-tokens/rotate', method: 'POST' });
|
return this.request({ url: '/api/user/auth-tokens/rotate', method: 'POST', retry: 1 });
|
||||||
}
|
}
|
||||||
|
|
||||||
loginPing() {
|
loginPing() {
|
||||||
|
Loading…
Reference in New Issue
Block a user