NewAPIKey creates a new API key instance
(name, ownerID string, scopes []string, expiresAt time.Time)
| 30 | |
| 31 | // NewAPIKey creates a new API key instance |
| 32 | func NewAPIKey(name, ownerID string, scopes []string, expiresAt time.Time) (*APIKey, error) { |
| 33 | key, err := GenerateKey() |
| 34 | if err != nil { |
| 35 | return nil, err |
| 36 | } |
| 37 | |
| 38 | return &APIKey{ |
| 39 | APIKeyID: GenerateUUIDWithSuffix("api_key"), |
| 40 | Key: key, |
| 41 | Name: name, |
| 42 | OwnerID: ownerID, |
| 43 | Scopes: scopes, |
| 44 | ExpiresAt: expiresAt, |
| 45 | CreatedAt: time.Now(), |
| 46 | }, nil |
| 47 | } |
| 48 | |
| 49 | // IsValid checks if the API key is valid |
| 50 | func (k *APIKey) IsValid() bool { |