2022-11-18 02:56:06 -06:00
|
|
|
package authimpl
|
2019-02-02 05:11:30 -06:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2022-11-18 02:56:06 -06:00
|
|
|
"github.com/grafana/grafana/pkg/services/auth"
|
2019-02-02 05:11:30 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
type userAuthToken struct {
|
|
|
|
Id int64
|
|
|
|
UserId int64
|
|
|
|
AuthToken string
|
|
|
|
PrevAuthToken string
|
|
|
|
UserAgent string
|
|
|
|
ClientIp string
|
|
|
|
AuthTokenSeen bool
|
|
|
|
SeenAt int64
|
|
|
|
RotatedAt int64
|
|
|
|
CreatedAt int64
|
|
|
|
UpdatedAt int64
|
2021-03-16 11:44:02 -05:00
|
|
|
RevokedAt int64
|
2019-02-02 05:11:30 -06:00
|
|
|
UnhashedToken string `xorm:"-"`
|
|
|
|
}
|
|
|
|
|
2022-11-18 02:56:06 -06:00
|
|
|
func userAuthTokenFromUserToken(ut *auth.UserToken) (*userAuthToken, error) {
|
2019-02-06 09:21:16 -06:00
|
|
|
var uat userAuthToken
|
2019-10-22 07:08:18 -05:00
|
|
|
err := uat.fromUserToken(ut)
|
|
|
|
return &uat, err
|
2019-02-02 05:11:30 -06:00
|
|
|
}
|
|
|
|
|
2022-11-18 02:56:06 -06:00
|
|
|
func (uat *userAuthToken) fromUserToken(ut *auth.UserToken) error {
|
2019-02-06 10:02:57 -06:00
|
|
|
if uat == nil {
|
|
|
|
return fmt.Errorf("needs pointer to userAuthToken struct")
|
|
|
|
}
|
|
|
|
|
2019-02-06 09:21:16 -06:00
|
|
|
uat.Id = ut.Id
|
|
|
|
uat.UserId = ut.UserId
|
|
|
|
uat.AuthToken = ut.AuthToken
|
|
|
|
uat.PrevAuthToken = ut.PrevAuthToken
|
|
|
|
uat.UserAgent = ut.UserAgent
|
|
|
|
uat.ClientIp = ut.ClientIp
|
|
|
|
uat.AuthTokenSeen = ut.AuthTokenSeen
|
|
|
|
uat.SeenAt = ut.SeenAt
|
|
|
|
uat.RotatedAt = ut.RotatedAt
|
|
|
|
uat.CreatedAt = ut.CreatedAt
|
|
|
|
uat.UpdatedAt = ut.UpdatedAt
|
2021-03-16 11:44:02 -05:00
|
|
|
uat.RevokedAt = ut.RevokedAt
|
2019-02-06 09:21:16 -06:00
|
|
|
uat.UnhashedToken = ut.UnhashedToken
|
2019-02-06 10:02:57 -06:00
|
|
|
|
|
|
|
return nil
|
2019-02-02 05:11:30 -06:00
|
|
|
}
|
|
|
|
|
2022-11-18 02:56:06 -06:00
|
|
|
func (uat *userAuthToken) toUserToken(ut *auth.UserToken) error {
|
2019-02-06 09:21:16 -06:00
|
|
|
if uat == nil {
|
|
|
|
return fmt.Errorf("needs pointer to userAuthToken struct")
|
2019-02-02 05:11:30 -06:00
|
|
|
}
|
|
|
|
|
2019-02-06 09:21:16 -06:00
|
|
|
ut.Id = uat.Id
|
|
|
|
ut.UserId = uat.UserId
|
|
|
|
ut.AuthToken = uat.AuthToken
|
|
|
|
ut.PrevAuthToken = uat.PrevAuthToken
|
|
|
|
ut.UserAgent = uat.UserAgent
|
|
|
|
ut.ClientIp = uat.ClientIp
|
|
|
|
ut.AuthTokenSeen = uat.AuthTokenSeen
|
|
|
|
ut.SeenAt = uat.SeenAt
|
|
|
|
ut.RotatedAt = uat.RotatedAt
|
|
|
|
ut.CreatedAt = uat.CreatedAt
|
|
|
|
ut.UpdatedAt = uat.UpdatedAt
|
2021-03-16 11:44:02 -05:00
|
|
|
ut.RevokedAt = uat.RevokedAt
|
2019-02-06 09:21:16 -06:00
|
|
|
ut.UnhashedToken = uat.UnhashedToken
|
|
|
|
return nil
|
2019-02-02 05:11:30 -06:00
|
|
|
}
|