# auth.token.create

Signs a JWT holding the --claim values

# auth.token.create

```
auth.token.create --credential TEXT [--ttl DURATION] [--claim KEY=EXPR…] [--issuer TEXT] [--audience TEXT] → token
```

Signs a JWT holding the `--claim` values. It is signed with a stored `jwt_signing_key` credential (HS256/384/512 or RS256/384/512, as the credential says), valid for `--ttl` (a duration, default 15m). Adds `token: { access_token, token_type, expires_in, profile }` and keeps the rest of the payload; `expires_in` is in seconds, as OAuth writes it. A claim whose name ends in `:public` (`--claim "name:public={{ input.fullname }}"`) is the only kind exposed in the browser via `ctx.auth`; all others stay server-only. A claim's value keeps the type its expression gives.

## Flags

- `--credential` (required): The jwt_signing_key credential that signs the token.
- `--ttl`: How long the token is valid, e.g. 15m, 1h or 1d (default 15m).
- `--claim`: A claim to sign, repeated: name=literal or name={{ expr }} (the value keeps its type). End the name with :public to expose it in the browser via ctx.auth, e.g. --claim "name:public={{ input.fullname }}"; the rest are signed but never reach the browser.
- `--issuer`: The iss claim.
- `--audience`: The aud claim.

## Examples

### Mint a session token after login

```
| auth.token.create --credential jwt_main --ttl 1d --claim "sub={{ input.query.rows[0]._key }}" --claim "name:public={{ input.query.rows[0].name }}" --claim "roles:public={{ input.query.rows[0].roles }}"
```

Then `web.response.send --status 303 --header "Location=/home" --header "Set-Cookie=zebflow_session={{ input.token.access_token }}; Path=/; Max-Age=86400; SameSite=Lax; HttpOnly"` (sent as written; add `; Secure` behind HTTPS). `roles` must be an array for a trigger's `--role`.

It answers:

```json
{
  "token": {
    "access_token": "eyJhbGciOiJIUzI1NiJ9…",
    "token_type": "bearer",
    "expires_in": 86400,
    "profile": {
      "name": "Ana",
      "roles": [
        "editor"
      ]
    }
  }
}
```

## Used in

- [Auth and Authorization](/examples/auth-and-authorization.md)
- [Blog with Admin](/examples/blog-with-admin.md)
- [Cookie + JWT Authentication](/examples/cookie-jwt-auth.md)
- [Sign in to a published MCP server (OAuth)](/examples/mcp-oauth-login.md)
- [Sign in with Google (OAuth login)](/examples/oauth-login-google.md)
