move UserToken and UserTokenService to models package

This commit is contained in:
Marcus Efraimsson
2019-02-06 16:55:12 +01:00
parent a60124a88c
commit 8678620730
12 changed files with 85 additions and 86 deletions
+1 -2
View File
@@ -4,7 +4,6 @@ import (
"strings"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/services/auth"
"github.com/grafana/grafana/pkg/services/session"
"github.com/grafana/grafana/pkg/setting"
"github.com/prometheus/client_golang/prometheus"
@@ -14,7 +13,7 @@ import (
type ReqContext struct {
*macaron.Context
*SignedInUser
UserToken *auth.UserToken
UserToken *UserToken
// This should only be used by the auth_proxy
Session session.SessionStore
+32
View File
@@ -0,0 +1,32 @@
package models
import "errors"
// Typed errors
var (
ErrUserTokenNotFound = errors.New("user token not found")
)
// UserToken represents a user token
type UserToken struct {
Id int64
UserId int64
AuthToken string
PrevAuthToken string
UserAgent string
ClientIp string
AuthTokenSeen bool
SeenAt int64
RotatedAt int64
CreatedAt int64
UpdatedAt int64
UnhashedToken string
}
// UserTokenService are used for generating and validating user tokens
type UserTokenService interface {
CreateToken(userId int64, clientIP, userAgent string) (*UserToken, error)
LookupToken(unhashedToken string) (*UserToken, error)
TryRotateToken(token *UserToken, clientIP, userAgent string) (bool, error)
RevokeToken(token *UserToken) error
}