mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 19:44:21 +00:00
7295383621
* fix: translation * fix: translation * fix: translation * fix: remove unused code * fix: log err
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package eventstore
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/caos/zitadel/internal/auth/repository/eventsourcing/view"
|
|
token_model "github.com/caos/zitadel/internal/token/model"
|
|
token_view_model "github.com/caos/zitadel/internal/token/repository/view/model"
|
|
)
|
|
|
|
type TokenRepo struct {
|
|
View *view.View
|
|
}
|
|
|
|
func (repo *TokenRepo) CreateToken(ctx context.Context, agentID, applicationID, userID string, audience, scopes []string, lifetime time.Duration) (*token_model.Token, error) {
|
|
preferredLanguage := ""
|
|
user, _ := repo.View.UserByID(userID)
|
|
if user != nil {
|
|
preferredLanguage = user.PreferredLanguage
|
|
}
|
|
token, err := repo.View.CreateToken(agentID, applicationID, userID, preferredLanguage, audience, scopes, lifetime)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return token_view_model.TokenToModel(token), nil
|
|
}
|
|
|
|
func (repo *TokenRepo) IsTokenValid(ctx context.Context, tokenID string) (bool, error) {
|
|
return repo.View.IsTokenValid(tokenID)
|
|
}
|
|
|
|
func (repo *TokenRepo) TokenByID(ctx context.Context, tokenID string) (*token_model.Token, error) {
|
|
token, err := repo.View.TokenByID(tokenID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return token_view_model.TokenToModel(token), nil
|
|
}
|