Skip to main content

create_token

Function create_token 

Source
pub async fn create_token(
    pool: &PgPool,
    actor: &Actor,
    name: &str,
    lifetime: TokenLifetime,
    scope: TokenScope,
) -> AppResult<(ApiToken, String)>
Expand description

Creates a personal access token. The plaintext is returned exactly once.

§Invariants

  • Permission: any signed-in actor; the token belongs to the actor and never carries more than the actor’s rights; the scope only narrows them. A lifetime outside 1 to 3650 days is refused (400).
  • Locks: none.
  • Data: only the hash and a short prefix are stored; the plaintext is not recoverable later.
  • Audit: token.create (name, scope and expiry, never the token).
  • Notifications / webhooks: none.
  • Atomic: one transaction.