mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-03 14:34:40 +00:00
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:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user