datumforge / datum

Datum's central server
https://datum.net
Apache License 2.0
53 stars 7 forks source link

[Bug] Token `LastUsed` not updated #1059

Open golanglemonade opened 1 week ago

golanglemonade commented 1 week ago

Describe the bug or issue you're encountering

When using a personal_access_token and ap_tokens, the lastUsed field is not being updated

What are the relevant steps to reproduce, including the version(s) of the relevant software?

Create a PAT

✗ go run cmd/cli/main.go pat create -n stuffff -d "for all the things" -e 730h -o 01J18E87D587GKK8K18MPYWER4

Check last_used

go run cmd/cli/main.go pat get                                                                            
  ID                          NAME     TOKEN                          LASTUSEDAT  EXPIRESAT                             
  01J18GR4DJH5Q17QA5J6J4C9E1  stuffff  *****************************  never       2024-07-26 06:17:43.84478 +0000 UTC   
  01J18GTHP3E244W8NHBGMZYTNF  stuffff  *****************************  never       2024-07-26 06:19:02.960658 +0000 UTC  

Use the PAT in a request, and recheck last_used - it will still be never

What is the expected behavior?

LastUsedAt is updated when PAT and API tokens are used

Code Location

This should be updated in the auth middleware that determines if the Token is valid before the AuthenticatedUser is returned https://github.com/datumforge/datum/blob/main/pkg/middleware/auth/auth.go