feat(api-token): store API tokens as SHA-256 hashes (#492)

New tokens are 32 random bytes with a shumai_ prefix and are returned
only once at creation. The list endpoint returns a 4-character hint
instead of the plaintext. A migration hashes existing tokens in place so
they keep authenticating.
This commit is contained in:
Yiling-J
2026-10-26 11:08:46 +08:00
committed by GitHub
parent c2af7494ec
commit 22486b893b
19 changed files with 413 additions and 113 deletions
+9 -1
View File
@@ -11,10 +11,18 @@ export const createApiTokenRequestSchema = z.object({
})
export type CreateApiTokenRequest = z.infer<typeof createApiTokenRequestSchema>
/** An API token as listed in settings. The plaintext is never returned after creation. */
export const apiTokenResponseSchema = z.object({
id: z.string(),
token: z.string(),
name: z.string(),
/** Last characters of the token, used to identify it in the UI. */
tokenHint: z.string(),
createdAt: z.string(),
})
export type ApiTokenResponse = z.infer<typeof apiTokenResponseSchema>
/** Returned once when a token is created; `token` is the only time the plaintext is exposed. */
export const createApiTokenResponseSchema = apiTokenResponseSchema.extend({
token: z.string(),
})
export type CreateApiTokenResponse = z.infer<typeof createApiTokenResponseSchema>