Add Bearer token authentication for API access #3
Labels
No labels
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Blocks
Depends on
#4 Add CLI config file management
austin/vektor
#2 Sign session tokens with HMAC
austin/vektor
Reference
austin/vektor#3
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The CLI needs a way to authenticate to the API without browser cookies. Currently only cookie-based sessions exist.
What needs to happen
Add a
POST /auth/tokenendpoint (behind auth) that generates and returns a long-lived API token. The token is returned once at creation and never stored in plaintext.New migration:
api_tokenstable with columns:idTEXT PRIMARY KEYuser_idTEXT NOT NULL REFERENCES users(id)token_hashTEXT NOT NULL (SHA256 — tokens are high-entropy random strings, fast hash is fine)nameTEXT NOT NULLcreated_atDATETIME DEFAULT CURRENT_TIMESTAMPexpires_atDATETIMEAuth middleware change: Check for
Authorization: Bearer <token>header in addition to session cookies. On Bearer auth, SHA256 hash the provided token and look it up inapi_tokens.Key files
internal/db/migrations.go— new migration forapi_tokenstableinternal/auth/— middleware update to check Bearer headerinternal/api/server.go— new route forPOST /auth/token