mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 02:40:26 -06:00
610999cfa2
* Add revoked_at field to user auth token to allow soft revokes * Allow soft token revocations * Update token revocations and tests * Return error info on revokedTokenErr * Override session cookie only when no revokedErr nor API request * Display modal on revoked token error * Feedback: Refactor TokenRevokedModal to FC * Add GetUserRevokedTokens into UserTokenService * Backendsrv: adds tests and refactors soft token path * Apply feedback * Write redirect cookie on token revoked error * Update TokenRevokedModal style * Return meaningful error info * Some UI changes * Update backend_srv tests * Minor style fix on backend_srv tests * Replace deprecated method usage to publish events * Fix backend_srv tests * Apply suggestions from code review Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com> Co-authored-by: Hugo Häggmark <hugo.haggmark@gmail.com> * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Hugo Häggmark <hugo.haggmark@gmail.com> * Minor style fix after PR suggestion commit * Apply suggestions from code review Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> * Prettier fixes Co-authored-by: Hugo Häggmark <hugo.haggmark@gmail.com> Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com> Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com>
74 lines
1.6 KiB
Go
74 lines
1.6 KiB
Go
package auth
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
)
|
|
|
|
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
|
|
RevokedAt int64
|
|
UnhashedToken string `xorm:"-"`
|
|
}
|
|
|
|
func userAuthTokenFromUserToken(ut *models.UserToken) (*userAuthToken, error) {
|
|
var uat userAuthToken
|
|
err := uat.fromUserToken(ut)
|
|
return &uat, err
|
|
}
|
|
|
|
func (uat *userAuthToken) fromUserToken(ut *models.UserToken) error {
|
|
if uat == nil {
|
|
return fmt.Errorf("needs pointer to userAuthToken struct")
|
|
}
|
|
|
|
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
|
|
uat.RevokedAt = ut.RevokedAt
|
|
uat.UnhashedToken = ut.UnhashedToken
|
|
|
|
return nil
|
|
}
|
|
|
|
func (uat *userAuthToken) toUserToken(ut *models.UserToken) error {
|
|
if uat == nil {
|
|
return fmt.Errorf("needs pointer to userAuthToken struct")
|
|
}
|
|
|
|
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
|
|
ut.RevokedAt = uat.RevokedAt
|
|
ut.UnhashedToken = uat.UnhashedToken
|
|
|
|
return nil
|
|
}
|