跳到内容
栏目
Fiesta

api-tokens

路由 这些片段本身就是一整个响应,而不是响应里的一块。

API 令牌页面:一次性显示、创建表单、列表和撤销按钮。

每个示例都能真实操作,但其中的链接不会跳转到任何地方。 HTML 显示可复制的标记。

四个令牌,其中两个有效

撤销表单提交到页面自身路径下的 /tokens/revoke、/tokens/revoke-agent 和 /tokens/revoke-all。把它们指向你的应用处理它们的地方。

预览
<div rst-tokens>
  <section rst-box>
    <form rst-form method="post" action="/tokens">
      <div rst-field>
        <label rst-field-label for="agent">代理名称</label>
        <input rst-input type="text" id="agent" name="agent" maxlength="40">
      </div>
      <label rst-switch>
        <input type="checkbox" name="for_self" value="on">
        <span rst-switch-track aria-hidden="true"></span>
        这个令牌是给我自己的,不是给代理的
      </label>
      <fieldset rst-choice>
        <legend>权限</legend>
        <div rst-choice-cards>
          <label>
            <input type="radio" name="access" value="write" checked>
            <span>
              <span rst-choice-title>读写</span>
            </span>
          </label>
          <label>
            <input type="radio" name="access" value="read">
            <span>
              <span rst-choice-title>只读</span>
            </span>
          </label>
        </div>
      </fieldset>
      <div rst-field>
        <label rst-field-label for="expiry">有效期至</label>
        <select rst-input="short" id="expiry" name="expiry">
          <option value="30">30 天</option>
          <option value="90" selected>90 天</option>
          <option value="365">1 年</option>
          <option value="never">永不</option>
        </select>
      </div>
      <div rst-form-foot>
        <button rst-btn="primary lg" type="submit">创建令牌</button>
      </div>
    </form>
  </section>
  <div rst-card rst-tokens-list role="table" aria-label="令牌">
    <div rst-lrow="head" role="row">
      <span role="columnheader">令牌</span>
      <span class="rst-m-hide" role="columnheader">权限</span>
      <span class="rst-m-hide" role="columnheader">创建时间</span>
      <span class="rst-m-hide" role="columnheader">上次使用</span>
      <span class="rst-m-hide" role="columnheader">有效期至</span>
      <span role="columnheader"><span class="rst-sr-only">状态</span></span>
      <span role="columnheader"><span class="rst-sr-only">操作</span></span>
    </div>
    <div rst-lrow role="row">
      <span class="rst-nm" role="rowheader"><span rst-actor>Claude(代表 Grace Hopper)</span>
        <small>
          <code>k3Jx9QpL2mWa</code>
        </small>
      </span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>权限</span>读写</span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>创建时间</span><time datetime="2026-08-02">2026-08-02</time></span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>上次使用</span><time datetime="2026-08-11">2026-08-11</time></span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>有效期至</span><time datetime="2026-10-31">2026-10-31</time></span>
      <span rst-tokens-state role="cell"></span>
      <span role="cell">
        <details rst-row-menu name="rst-menus">
          <summary aria-label="Claude(代表 Grace Hopper) 的操作">
            <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="1"/><circle cx="12" cy="5" r="1"/><circle cx="12" cy="19" r="1"/></svg>
          </summary>
          <div rst-row-menu-panel>
            <form method="post" action="/tokens/revoke">
              <input type="hidden" name="id" value="k3Jx9QpL2mWa">
              <button type="submit">撤销</button>
            </form>
          </div>
        </details>
      </span>
    </div>
    <div rst-lrow role="row">
      <span class="rst-nm" role="rowheader"><span rst-actor>Grace Hopper</span>
        <small>
          <code>Qm2vR8sT4xYb</code>
        </small>
      </span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>权限</span>只读</span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>创建时间</span><time datetime="2026-08-02">2026-08-02</time></span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>上次使用</span></span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>有效期至</span>永不</span>
      <span rst-tokens-state role="cell"></span>
      <span role="cell">
        <details rst-row-menu name="rst-menus">
          <summary aria-label="Grace Hopper 的操作">
            <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="1"/><circle cx="12" cy="5" r="1"/><circle cx="12" cy="19" r="1"/></svg>
          </summary>
          <div rst-row-menu-panel>
            <form method="post" action="/tokens/revoke">
              <input type="hidden" name="id" value="Qm2vR8sT4xYb">
              <button type="submit">撤销</button>
            </form>
          </div>
        </details>
      </span>
    </div>
    <div rst-lrow role="row">
      <span class="rst-nm" role="rowheader"><span rst-actor>Codex(代表 Grace Hopper)</span>
        <small>
          <code>Zp7wN1cH6kLd</code>
        </small>
      </span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>权限</span>读写</span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>创建时间</span><time datetime="2026-08-02">2026-08-02</time></span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>上次使用</span></span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>有效期至</span>永不</span>
      <span rst-tokens-state role="cell"><span rst-status rst-tone="neutral">已撤销</span></span>
    </div>
    <div rst-lrow role="row">
      <span class="rst-nm" role="rowheader"><span rst-actor>夜间导入(代表 Grace Hopper)</span>
        <small>
          <code>Vb4tG9yK3nMe</code>
        </small>
      </span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>权限</span>只读</span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>创建时间</span><time datetime="2026-08-02">2026-08-02</time></span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>上次使用</span></span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>有效期至</span><time datetime="2026-08-11">2026-08-11</time></span>
      <span rst-tokens-state role="cell"><span rst-status rst-tone="warning">已过期</span></span>
    </div>
  </div>
  <div rst-tokens-revoke>
    <form method="post" action="/tokens/revoke-agent">
      <input type="hidden" name="agent" value="Claude">
      <button rst-btn type="submit">撤销这个代理的全部令牌:Claude</button>
    </form>
    <form method="post" action="/tokens/revoke-all">
      <button rst-btn="danger" type="submit">撤销全部令牌</button>
    </form>
  </div>
</div>

在应用里,这会到达 /tokens, /tokens/revoke, /tokens/revoke-agent, /tokens/revoke-all。在这里,它的链接和表单哪儿也不去。

刚创建:秘密只显示一次

在创建表单本身的响应里显示这个,并且不要重定向:秘密只在那个响应里,别处没有。

预览
<div rst-tokens>
  <div rst-callout rst-tone="positive" tabindex="-1" autofocus>
    <span rst-callout-ic aria-hidden="true">
      <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="10"/><path d="m9 12 2 2 4-4"/></svg>
    </span>
    <div rst-callout-body>
      <strong>现在就复制这个令牌。它不会再显示。</strong>
      <p>
        <code rst-tokens-secret>harbour_k3Jx9QpL2mWa_6bD2qK9xWz4rT8vN1mP3sL7yF5hJ0cG2aE4uB</code>
      </p>
    </div>
  </div>
  <section rst-box>
    <form rst-form method="post" action="/tokens">
      <div rst-field>
        <label rst-field-label for="agent">代理名称</label>
        <input rst-input type="text" id="agent" name="agent" maxlength="40">
      </div>
      <label rst-switch>
        <input type="checkbox" name="for_self" value="on">
        <span rst-switch-track aria-hidden="true"></span>
        这个令牌是给我自己的,不是给代理的
      </label>
      <fieldset rst-choice>
        <legend>权限</legend>
        <div rst-choice-cards>
          <label>
            <input type="radio" name="access" value="write" checked>
            <span>
              <span rst-choice-title>读写</span>
            </span>
          </label>
          <label>
            <input type="radio" name="access" value="read">
            <span>
              <span rst-choice-title>只读</span>
            </span>
          </label>
        </div>
      </fieldset>
      <div rst-field>
        <label rst-field-label for="expiry">有效期至</label>
        <select rst-input="short" id="expiry" name="expiry">
          <option value="30">30 天</option>
          <option value="90" selected>90 天</option>
          <option value="365">1 年</option>
          <option value="never">永不</option>
        </select>
      </div>
      <div rst-form-foot>
        <button rst-btn="primary lg" type="submit">创建令牌</button>
      </div>
    </form>
  </section>
  <div rst-card rst-tokens-list role="table" aria-label="令牌">
    <div rst-lrow="head" role="row">
      <span role="columnheader">令牌</span>
      <span class="rst-m-hide" role="columnheader">权限</span>
      <span class="rst-m-hide" role="columnheader">创建时间</span>
      <span class="rst-m-hide" role="columnheader">上次使用</span>
      <span class="rst-m-hide" role="columnheader">有效期至</span>
      <span role="columnheader"><span class="rst-sr-only">状态</span></span>
      <span role="columnheader"><span class="rst-sr-only">操作</span></span>
    </div>
    <div rst-lrow role="row">
      <span class="rst-nm" role="rowheader"><span rst-actor>Claude(代表 Grace Hopper)</span>
        <small>
          <code>k3Jx9QpL2mWa</code>
        </small>
      </span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>权限</span>读写</span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>创建时间</span><time datetime="2026-08-02">2026-08-02</time></span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>上次使用</span><time datetime="2026-08-11">2026-08-11</time></span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>有效期至</span><time datetime="2026-10-31">2026-10-31</time></span>
      <span rst-tokens-state role="cell"></span>
      <span role="cell">
        <details rst-row-menu name="rst-menus">
          <summary aria-label="Claude(代表 Grace Hopper) 的操作">
            <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="1"/><circle cx="12" cy="5" r="1"/><circle cx="12" cy="19" r="1"/></svg>
          </summary>
          <div rst-row-menu-panel>
            <form method="post" action="/tokens/revoke">
              <input type="hidden" name="id" value="k3Jx9QpL2mWa">
              <button type="submit">撤销</button>
            </form>
          </div>
        </details>
      </span>
    </div>
    <div rst-lrow role="row">
      <span class="rst-nm" role="rowheader"><span rst-actor>Grace Hopper</span>
        <small>
          <code>Qm2vR8sT4xYb</code>
        </small>
      </span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>权限</span>只读</span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>创建时间</span><time datetime="2026-08-02">2026-08-02</time></span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>上次使用</span></span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>有效期至</span>永不</span>
      <span rst-tokens-state role="cell"></span>
      <span role="cell">
        <details rst-row-menu name="rst-menus">
          <summary aria-label="Grace Hopper 的操作">
            <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="1"/><circle cx="12" cy="5" r="1"/><circle cx="12" cy="19" r="1"/></svg>
          </summary>
          <div rst-row-menu-panel>
            <form method="post" action="/tokens/revoke">
              <input type="hidden" name="id" value="Qm2vR8sT4xYb">
              <button type="submit">撤销</button>
            </form>
          </div>
        </details>
      </span>
    </div>
    <div rst-lrow role="row">
      <span class="rst-nm" role="rowheader"><span rst-actor>Codex(代表 Grace Hopper)</span>
        <small>
          <code>Zp7wN1cH6kLd</code>
        </small>
      </span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>权限</span>读写</span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>创建时间</span><time datetime="2026-08-02">2026-08-02</time></span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>上次使用</span></span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>有效期至</span>永不</span>
      <span rst-tokens-state role="cell"><span rst-status rst-tone="neutral">已撤销</span></span>
    </div>
    <div rst-lrow role="row">
      <span class="rst-nm" role="rowheader"><span rst-actor>夜间导入(代表 Grace Hopper)</span>
        <small>
          <code>Vb4tG9yK3nMe</code>
        </small>
      </span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>权限</span>只读</span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>创建时间</span><time datetime="2026-08-02">2026-08-02</time></span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>上次使用</span></span>
      <span rst-tokens-fact role="cell"><span rst-tokens-fact-label>有效期至</span><time datetime="2026-08-11">2026-08-11</time></span>
      <span rst-tokens-state role="cell"><span rst-status rst-tone="warning">已过期</span></span>
    </div>
  </div>
  <div rst-tokens-revoke>
    <form method="post" action="/tokens/revoke-agent">
      <input type="hidden" name="agent" value="Claude">
      <button rst-btn type="submit">撤销这个代理的全部令牌:Claude</button>
    </form>
    <form method="post" action="/tokens/revoke-all">
      <button rst-btn="danger" type="submit">撤销全部令牌</button>
    </form>
  </div>
</div>

在应用里,这会到达 /tokens, /tokens/revoke, /tokens/revoke-agent, /tokens/revoke-all。在这里,它的链接和表单哪儿也不去。

还没有令牌

预览
<div rst-tokens>
  <section rst-box>
    <form rst-form method="post" action="/tokens">
      <div rst-field>
        <label rst-field-label for="agent">代理名称</label>
        <input rst-input type="text" id="agent" name="agent" maxlength="40">
      </div>
      <label rst-switch>
        <input type="checkbox" name="for_self" value="on">
        <span rst-switch-track aria-hidden="true"></span>
        这个令牌是给我自己的,不是给代理的
      </label>
      <fieldset rst-choice>
        <legend>权限</legend>
        <div rst-choice-cards>
          <label>
            <input type="radio" name="access" value="write" checked>
            <span>
              <span rst-choice-title>读写</span>
            </span>
          </label>
          <label>
            <input type="radio" name="access" value="read">
            <span>
              <span rst-choice-title>只读</span>
            </span>
          </label>
        </div>
      </fieldset>
      <div rst-field>
        <label rst-field-label for="expiry">有效期至</label>
        <select rst-input="short" id="expiry" name="expiry">
          <option value="30">30 天</option>
          <option value="90" selected>90 天</option>
          <option value="365">1 年</option>
          <option value="never">永不</option>
        </select>
      </div>
      <div rst-form-foot>
        <button rst-btn="primary lg" type="submit">创建令牌</button>
      </div>
    </form>
  </section>
  <div rst-empty>
    <p rst-empty-body>还没有令牌。</p>
  </div>
</div>

在应用里,这会到达 /tokens。在这里,它的链接和表单哪儿也不去。