ValidateAPIKey validates a raw API key and returns the associated APIKey if valid
(ctx context.Context, rawKey string)
| 265 | |
| 266 | // ValidateAPIKey validates a raw API key and returns the associated APIKey if valid |
| 267 | func (s *APIKeyStore) ValidateAPIKey(ctx context.Context, rawKey string) (*APIKey, error) { |
| 268 | keyHash := HashAPIKey(rawKey) |
| 269 | |
| 270 | apiKey, err := s.GetByHash(ctx, keyHash) |
| 271 | if err != nil { |
| 272 | if errors.Is(err, ErrAPIKeyNotFound) { |
| 273 | return nil, ErrInvalidAPIKey |
| 274 | } |
| 275 | return nil, err |
| 276 | } |
| 277 | |
| 278 | // Update last used timestamp asynchronously |
| 279 | go func() { |
| 280 | _ = s.UpdateLastUsed(ctx, apiKey.ID) |
| 281 | }() |
| 282 | |
| 283 | return apiKey, nil |
| 284 | } |
nothing calls this directly
no test coverage detected