[v9.4.x] Auth: Rotate token patch (#62782)

Auth: Rotate token patch (#62676)

* Use singleflight.Group

* Align tests

* Cleanup

(cherry picked from commit 7c1d9769ca)

Co-authored-by: Misi <mgyongyosi@users.noreply.github.com>
This commit is contained in:
Grot (@grafanabot)
2023-02-02 18:05:38 +01:00
committed by GitHub
co-authored by Misi
parent 363171b182
commit d31f932800
9 changed files with 122 additions and 88 deletions
+2 -1
View File
@@ -107,13 +107,14 @@ func (s *Session) RefreshTokenHook(ctx context.Context, identity *authn.Identity
s.log.Debug("failed to get client IP address", "addr", addr, "err", err)
ip = nil
}
rotated, err := s.sessionService.TryRotateToken(ctx, identity.SessionToken, ip, userAgent)
rotated, newToken, err := s.sessionService.TryRotateToken(ctx, identity.SessionToken, ip, userAgent)
if err != nil {
s.log.Error("failed to rotate token", "error", err)
return
}
if rotated {
identity.SessionToken = newToken
s.log.Debug("rotated session token", "user", identity.ID)
maxAge := int(s.loginMaxLifetime.Seconds())
+2 -2
View File
@@ -143,9 +143,9 @@ func (f *fakeResponseWriter) WriteHeader(statusCode int) {
func TestSession_RefreshHook(t *testing.T) {
s := ProvideSession(&authtest.FakeUserAuthTokenService{
TryRotateTokenProvider: func(ctx context.Context, token *auth.UserToken, clientIP net.IP, userAgent string) (bool, error) {
TryRotateTokenProvider: func(ctx context.Context, token *auth.UserToken, clientIP net.IP, userAgent string) (bool, *auth.UserToken, error) {
token.UnhashedToken = "new-token"
return true, nil
return true, token, nil
},
}, &usertest.FakeUserService{}, "grafana-session", 20*time.Second)