Auth: add expired token error and update CreateToken function (#30203)

* Auth: add error for expired token

* Auth: save token error into context data

* Auth: send full user and req context to CreateToken

* Auth: add token ID in context

* add TokenExpiredError struct

* update auth tests

* remove most of the changes to CreateToken func

* clean up

* Login: add requestURI in CreateToken ctx

* update RequestURIKey comment
This commit is contained in:
Agnès Toulet
2021-01-19 17:55:53 +01:00
committed by GitHub
parent 218a8de220
commit 2a70c73025
7 changed files with 47 additions and 25 deletions
+4 -1
View File
@@ -1,6 +1,7 @@
package api
import (
"context"
"encoding/hex"
"errors"
"net/http"
@@ -259,10 +260,12 @@ func (hs *HTTPServer) loginUserWithUser(user *models.User, c *models.ReqContext)
}
hs.log.Debug("Got IP address from client address", "addr", addr, "ip", ip)
userToken, err := hs.AuthTokenService.CreateToken(c.Req.Context(), user.Id, ip, c.Req.UserAgent())
ctx := context.WithValue(c.Req.Context(), models.RequestURIKey{}, c.Req.RequestURI)
userToken, err := hs.AuthTokenService.CreateToken(ctx, user, ip, c.Req.UserAgent())
if err != nil {
return errutil.Wrap("failed to create auth token", err)
}
c.UserToken = userToken
hs.log.Info("Successful Login", "User", user.Email)
cookies.WriteSessionCookie(c, hs.Cfg, userToken.UnhashedToken, hs.Cfg.LoginMaxLifetime)