2021-05-20 11:33:35 +00:00
|
|
|
package view
|
|
|
|
|
|
|
|
import (
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/zitadel/internal/errors"
|
|
|
|
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
|
|
|
user_model "github.com/zitadel/zitadel/internal/user/model"
|
|
|
|
usr_view "github.com/zitadel/zitadel/internal/user/repository/view"
|
|
|
|
"github.com/zitadel/zitadel/internal/user/repository/view/model"
|
|
|
|
"github.com/zitadel/zitadel/internal/view/repository"
|
2021-05-20 11:33:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
refreshTokenTable = "auth.refresh_tokens"
|
|
|
|
)
|
|
|
|
|
2022-04-19 06:26:12 +00:00
|
|
|
func (v *View) RefreshTokenByID(tokenID, instanceID string) (*model.RefreshTokenView, error) {
|
|
|
|
return usr_view.RefreshTokenByID(v.Db, refreshTokenTable, tokenID, instanceID)
|
2021-05-20 11:33:35 +00:00
|
|
|
}
|
|
|
|
|
2022-04-19 06:26:12 +00:00
|
|
|
func (v *View) RefreshTokensByUserID(userID, instanceID string) ([]*model.RefreshTokenView, error) {
|
|
|
|
return usr_view.RefreshTokensByUserID(v.Db, refreshTokenTable, userID, instanceID)
|
2021-05-20 11:33:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *View) SearchRefreshTokens(request *user_model.RefreshTokenSearchRequest) ([]*model.RefreshTokenView, uint64, error) {
|
|
|
|
return usr_view.SearchRefreshTokens(v.Db, refreshTokenTable, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *View) PutRefreshToken(token *model.RefreshTokenView, event *models.Event) error {
|
|
|
|
err := usr_view.PutRefreshToken(v.Db, refreshTokenTable, token)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return v.ProcessedTokenSequence(event)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *View) PutRefreshTokens(token []*model.RefreshTokenView, event *models.Event) error {
|
|
|
|
err := usr_view.PutRefreshTokens(v.Db, refreshTokenTable, token...)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return v.ProcessedRefreshTokenSequence(event)
|
|
|
|
}
|
|
|
|
|
2022-04-19 06:26:12 +00:00
|
|
|
func (v *View) DeleteRefreshToken(tokenID, instanceID string, event *models.Event) error {
|
|
|
|
err := usr_view.DeleteRefreshToken(v.Db, refreshTokenTable, tokenID, instanceID)
|
2021-05-20 11:33:35 +00:00
|
|
|
if err != nil && !errors.IsNotFound(err) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return v.ProcessedRefreshTokenSequence(event)
|
|
|
|
}
|
|
|
|
|
2022-04-19 06:26:12 +00:00
|
|
|
func (v *View) DeleteUserRefreshTokens(userID, instanceID string, event *models.Event) error {
|
|
|
|
err := usr_view.DeleteUserRefreshTokens(v.Db, refreshTokenTable, userID, instanceID)
|
2021-05-20 11:33:35 +00:00
|
|
|
if err != nil && !errors.IsNotFound(err) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return v.ProcessedRefreshTokenSequence(event)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *View) DeleteApplicationRefreshTokens(event *models.Event, ids ...string) error {
|
2022-04-19 06:26:12 +00:00
|
|
|
err := usr_view.DeleteApplicationTokens(v.Db, refreshTokenTable, event.InstanceID, ids)
|
2021-05-20 11:33:35 +00:00
|
|
|
if err != nil && !errors.IsNotFound(err) {
|
2022-10-26 13:06:48 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return v.ProcessedRefreshTokenSequence(event)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *View) DeleteInstanceRefreshTokens(event *models.Event) error {
|
|
|
|
err := usr_view.DeleteInstanceRefreshTokens(v.Db, refreshTokenTable, event.InstanceID)
|
|
|
|
if err != nil && !errors.IsNotFound(err) {
|
2022-11-30 16:01:17 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return v.ProcessedRefreshTokenSequence(event)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *View) DeleteOrgRefreshTokens(event *models.Event) error {
|
|
|
|
err := usr_view.DeleteOrgRefreshTokens(v.Db, refreshTokenTable, event.InstanceID, event.ResourceOwner)
|
|
|
|
if err != nil && !errors.IsNotFound(err) {
|
2021-05-20 11:33:35 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return v.ProcessedRefreshTokenSequence(event)
|
|
|
|
}
|
|
|
|
|
2022-04-19 06:26:12 +00:00
|
|
|
func (v *View) GetLatestRefreshTokenSequence(instanceID string) (*repository.CurrentSequence, error) {
|
|
|
|
return v.latestSequence(refreshTokenTable, instanceID)
|
|
|
|
}
|
|
|
|
|
2022-11-22 06:36:48 +00:00
|
|
|
func (v *View) GetLatestRefreshTokenSequences(instanceIDs []string) ([]*repository.CurrentSequence, error) {
|
|
|
|
return v.latestSequences(refreshTokenTable, instanceIDs)
|
2021-05-20 11:33:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *View) ProcessedRefreshTokenSequence(event *models.Event) error {
|
|
|
|
return v.saveCurrentSequence(refreshTokenTable, event)
|
|
|
|
}
|
|
|
|
|
2022-11-22 06:36:48 +00:00
|
|
|
func (v *View) UpdateRefreshTokenSpoolerRunTimestamp(instanceIDs []string) error {
|
|
|
|
return v.updateSpoolerRunSequence(refreshTokenTable, instanceIDs)
|
2021-05-20 11:33:35 +00:00
|
|
|
}
|
|
|
|
|
2022-04-19 06:26:12 +00:00
|
|
|
func (v *View) GetLatestRefreshTokenFailedEvent(sequence uint64, instanceID string) (*repository.FailedEvent, error) {
|
|
|
|
return v.latestFailedEvent(refreshTokenTable, instanceID, sequence)
|
2021-05-20 11:33:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *View) ProcessedRefreshTokenFailedEvent(failedEvent *repository.FailedEvent) error {
|
|
|
|
return v.saveFailedEvent(failedEvent)
|
|
|
|
}
|