mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
@@ -46,6 +46,10 @@ type LoginInfo struct {
|
||||
Error error
|
||||
}
|
||||
|
||||
// RequestURIKey is used as key to save request URI in contexts
|
||||
// (used for the Enterprise auditing feature)
|
||||
type RequestURIKey struct{}
|
||||
|
||||
// ---------------------
|
||||
// COMMANDS
|
||||
|
||||
|
||||
@@ -11,6 +11,13 @@ var (
|
||||
ErrUserTokenNotFound = errors.New("user token not found")
|
||||
)
|
||||
|
||||
type TokenExpiredError struct {
|
||||
UserID int64
|
||||
TokenID int64
|
||||
}
|
||||
|
||||
func (e *TokenExpiredError) Error() string { return "user token expired" }
|
||||
|
||||
// UserToken represents a user token
|
||||
type UserToken struct {
|
||||
Id int64
|
||||
@@ -33,7 +40,7 @@ type RevokeAuthTokenCmd struct {
|
||||
|
||||
// UserTokenService are used for generating and validating user tokens
|
||||
type UserTokenService interface {
|
||||
CreateToken(ctx context.Context, userId int64, clientIP net.IP, userAgent string) (*UserToken, error)
|
||||
CreateToken(ctx context.Context, user *User, clientIP net.IP, userAgent string) (*UserToken, error)
|
||||
LookupToken(ctx context.Context, unhashedToken string) (*UserToken, error)
|
||||
TryRotateToken(ctx context.Context, token *UserToken, clientIP net.IP, userAgent string) (bool, error)
|
||||
RevokeToken(ctx context.Context, token *UserToken) error
|
||||
|
||||
Reference in New Issue
Block a user