AgentStack
SKILL verified MIT Self-run

Br Single Use Token

skill-lonsdale201-wp-agent-skills-br-single-use-token · by Lonsdale201

Use better-route 0.6.0 SingleUseTokenMiddleware and stores for auth codes, reset links, magic links, email confirmation tokens, or any token that must be consumed exactly once. Triggers on SingleUseTokenMiddleware, SingleUseTokenStoreInterface, WpdbSingleUseTokenStore, WpCacheSingleUseTokenStore, ArraySingleUseTokenStore, token replay, single-use code, one-time token, or auth-code TOCTOU fixes. U…

No reviews yet
0 installs
6 views
0.0% view→install

Install

$ agentstack add skill-lonsdale201-wp-agent-skills-br-single-use-token

✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

Are you the author of Br Single Use Token? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

better-route: Single-use tokens

Use this when a token must be atomically consumed before a handler continues. Common examples: OAuth authorization codes, password reset tokens, magic links, invite tokens, and email confirmation tokens.

Pattern

use BetterRoute\Middleware\Write\SingleUseTokenMiddleware;
use BetterRoute\Middleware\Write\WpdbSingleUseTokenStore;

register_activation_hook(__FILE__, static function (): void {
    (new WpdbSingleUseTokenStore())->installSchema();
});

$singleUse = new SingleUseTokenMiddleware(
    store: new WpdbSingleUseTokenStore(),
    tokenSource: static fn ($request): ?string => $request->get_param('code'),
    hashSalt: MYAPP_SINGLE_USE_TOKEN_SALT,
    ttlSeconds: 300
);

$router->post('/oauth/token', $handler)
    ->middleware([$singleUse])
    ->publicRoute();

Store a token before it is used:

$singleUse->storeToken($rawCode, [
    'client_id' => $clientId,
    'redirect_uri' => $redirectUri,
    'subject' => $userId,
], ttlSeconds: 120);

Store choices

  • WpdbSingleUseTokenStore: production default when DB writes are acceptable; call installSchema() on activation.
  • WpCacheSingleUseTokenStore: object-cache lock plus transient-backed record; useful when DB table migration is not desired.
  • ArraySingleUseTokenStore: tests only.

Critical rules

  • Never store raw token values. Use storeToken() or hashToken() with a dedicated salt.
  • Use a salt dedicated to the token class or application; do not reuse OAuth client secrets as storage salts.
  • Consume before issuing side effects. If consume returns null, fail closed.
  • A reused token returns conflict semantics (single_use_token_reused).
  • Unknown or expired tokens fail as invalid.
  • Keep TTL short for auth codes; use longer TTL only for flows such as password reset where product requirements demand it.

Cross-references

  • Use br-atomic-idempotency for retry-safe side-effectful writes; that is different from one-time token consumption.
  • Use br-crypto for generating the raw one-time token.
  • Use br-error-contract for 401 invalid_single_use_token and 409 single_use_token_reused.

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet — be the first.

Versions

  • v0.1.0 Imported from the upstream source.