mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 01:37:31 +00:00
feat: add personal access tokens for service users (#2974)
* feat: add machine tokens * fix test * rename to pat * fix merge and tests * fix scopes * fix migration version * fix test * Update internal/repository/user/personal_access_token.go Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com> Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com>
This commit is contained in:
36
internal/domain/expiration.go
Normal file
36
internal/domain/expiration.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
//most of us won't survive until 12-31-9999 23:59:59, maybe ZITADEL does
|
||||
defaultExpDate = time.Date(9999, time.December, 31, 23, 59, 59, 0, time.UTC)
|
||||
)
|
||||
|
||||
type expiration interface {
|
||||
expirationDate() time.Time
|
||||
setExpirationDate(time.Time)
|
||||
}
|
||||
|
||||
func EnsureValidExpirationDate(key expiration) error {
|
||||
date, err := ValidateExpirationDate(key.expirationDate())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
key.setExpirationDate(date)
|
||||
return nil
|
||||
}
|
||||
|
||||
func ValidateExpirationDate(date time.Time) (time.Time, error) {
|
||||
if date.IsZero() {
|
||||
return defaultExpDate, nil
|
||||
}
|
||||
if date.Before(time.Now()) {
|
||||
return time.Time{}, errors.ThrowInvalidArgument(nil, "DOMAIN-dv3t5", "Errors.AuthNKey.ExpireBeforeNow")
|
||||
}
|
||||
return date, nil
|
||||
}
|
Reference in New Issue
Block a user