Add api keys

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Sacha Al Himdani
2025-11-03 09:15:14 +01:00
parent 845652c382
commit 5212d0c18f
47 changed files with 6009 additions and 3648 deletions

View File

@@ -66,13 +66,15 @@ func (e ErrExpiredToken) Error() string {
return e.message
}
// NewToken creates a new token with the specified type, data, and expiration time
func NewToken[T any](secret string, tokenType string, expirationTime time.Duration, data T) (string, error) {
now := time.Now()
return NewDeterministicToken(secret, tokenType, now.Add(expirationTime), now, data)
}
func NewDeterministicToken[T any](secret string, tokenType string, expiresAt time.Time, issuedAt time.Time, data T) (string, error) {
payload := Payload[T]{
ExpiresAt: now.Add(expirationTime),
IssuedAt: now,
ExpiresAt: expiresAt,
IssuedAt: issuedAt,
Type: tokenType,
Data: data,
}