agentleFS
PaldomPaldom/2fa-agents/skills/totp-provider-api/SKILL.md

totp-provider-api

Skill0 starsChanged 3 months agoMITView on GitHub

Fetches 2FA codes from a managed provider's API or CLI - 1Password (op), Bitwarden (bw), Vault's TOTP engine, 2FAuth - so the seed never lands on this machine. Use for an OTP from a password manager or team-shared 2FA, when such a CLI returns an ambiguous item or more than one result, or when asking whether a provider has a usable API. Not for local seed files or offline generation.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Do you hold the seed?: If yes — a file, keychain entry, or otpauth:// URI on this machine — that is totp-generate plus totp-secret-store.

    line 17
  2. Distinctive:

    Always prefer a dedicated machine account at the upstream service over a human's personal 2FA.

    line 107
  3. Distinctive:

    Never echo the token. A fetched code is short-lived but is still a credential — do not print it in CI output, and remember CI secret …

    line 112

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

totp-provider-api

Get a code from a provider that holds the seed for you. The machine running the agent never has the secret, the provider logs every request, and access is revoked by disabling a token rather than by chasing files. Fixes the failure that wastes the most time here: a vendor CLI silently falling back to an interactive unlock, so an unattended job hangs until it is killed.

Which skill, in one question

Do you hold the seed? If yes — a file, keychain entry, or otpauth:// URI on this machine — that is totp-generate plus totp-secret-store. If the seed lives in a vault you authenticate to and never see, it is this skill. op item get --otp computes locally inside the op binary, but you never hold the seed, so it is here.

When NOT to use

  • Generating from a seed you have → totp-generate.
  • Choosing where a seed you hold should live → totp-secret-store.
  • Serving codes to MCP clients → totp-mcp-server. Driving the login → login-2fa-flow.
  • Verifying your end users' TOTP codes (you are the service, they are the user) — that is Twilio Verify / an application TOTP library, the opposite direction. Not this skill.

Provider reality check

ProviderHow a code is fetchedAuth
1Passwordop item get ITEM --otp; op read "op://v/i/one-time password?attribute=otp"; SDK secrets.resolve(...)OP_SERVICE_ACCOUNT_TOKEN
Bitwardenbw get totp ITEM_IDBW_SESSION from bw unlock --raw
HashiCorp VaultGET /v1/totp/code/:name — plain HTTP, no client neededX-Vault-Token
2FAuth (self-hosted)GET /api/v1/twofaccounts/{id}/otpAuthorization: Bearer PAT
Google AuthenticatorNo API exists.—

Google Authenticator is a phone app with no server API and no CLI. Its only egress is the otpauth-migration://offline?data=… export QR — an undocumented, reverse-engineered protobuf. If someone asks to "use the Google Authenticator API", say it does not exist and pick from the rows above. Decode the migration blob once into otpauth:// URIs and move on.

Best pure-HTTP API: Vault (one GET, a token header, every request audited). Best if the team already has it: 1Password (service accounts are built for this). Best fully self-hosted with a UI: 2FAuth.

Workflow

1. Check the credential before you call anything

FETCH="${CLAUDE_SKILL_DIR}/scripts/fetch_code.py"
python3 "$FETCH" check          # which providers are installed and credentialed

op and bw prompt for an interactive unlock when their credential is missing — in CI or an unattended agent that is a hang, not an error. The script checks first, closes stdin, and enforces a 30 s timeout, so it always fails fast and loudly.

2. Fetch

python3 "$FETCH" 1password "GitHub" --vault Automation --min-validity 5
python3 "$FETCH" bitwarden 99ee88d2-0000-0000-0000-000000000000 --min-validity 5
python3 "$FETCH" vault github --addr https://vault.internal:8200
python3 "$FETCH" 2fauth 3 --url https://2fauth.internal

Use --min-validity 5 whenever the code is going into a form. A provider returns bare digits with no hint of how long they last, and the network round trip is pure loss on top. TOTP windows are absolute — floor(unix_time / period) is the same window for you and for the issuer — so the script can wait for a fresh window before fetching. Without it, a code fetched near a boundary is rejected in a way indistinguishable from a wrong seed, and it costs one of your two login attempts. Pass --period if the account does not use 30 seconds.

One code on stdout, exit 0. Non-zero and nothing on stdout otherwise: 3 not found or ambiguous, 5 credential missing/expired, 6 timeout, 7 provider error. This is the same code command contract the rest of these skills consume — anything that prints one code and exits 0 is interchangeable. The script also refuses output that is not exactly one code-shaped line, so a bw sync notice or an op deprecation banner can never be submitted as a code.

Raw vendor equivalents, when the script is not available:

op item get "GitHub" --otp                                     # not with --fields
op read "op://Automation/GitHub/one-time password?attribute=otp"
bw get totp "$ITEM_ID" --nointeraction
curl -sH "X-Vault-Token: $VAULT_TOKEN" "$VAULT_ADDR/v1/totp/code/github" | jq -r .data.code
curl -sH "Authorization: Bearer $TWOFAUTH_TOKEN" "$TWOFAUTH_URL/api/v1/twofaccounts/3/otp" | jq -r .password

3. Scope the credential

  • 1Password: a service account with access to one dedicated vault. Service accounts cannot reach Private vaults, and --vault is required once more than one is visible. OP_CONNECT_HOST/OP_CONNECT_TOKEN take precedence over the service account token — unset them if a Connect setup is interfering.
  • Vault: a policy granting read on exactly totp/code/<name>. Do not grant totp/keys/*, which exposes the seed URL.
  • 2FAuth: a personal access token, revocable in Settings. It is valid until revoked.
  • Always prefer a dedicated machine account at the upstream service over a human's personal 2FA.

4. Keep it out of the logs

Never echo the token. A fetched code is short-lived but is still a credential — do not print it in CI output, and remember CI secret masking only covers registered secrets, not values a provider returns at run time.

Output spec

  • One code on stdout; the token never appears in output, logs, or the transcript.
  • The provider, the item identity used, and the credential source were stated.
  • Non-zero exits surfaced verbatim — each message names the fix.

Gotchas

SymptomCause and fix
op/bw hangs forever in CIFalling back to an interactive unlock — set the token/session; a longer timeout is not a fix
More than one result was foundAmbiguous item name — use the item ID
cannot use '--otp' and '--fields' togetherFetch the password and the OTP as two calls
op read returns otpauth://… instead of digitsMissing ?attribute=otp — you got the seed, not the code
Service account cannot see the itemIt is in a Private vault, or the vault was never shared with the account
Vault 403 on totp/code/xPolicy grants the key path but not the code path
2FAuth returns HTMLBase URL points at the web UI, not /api/v1
Codes fine locally, rejected from CIProvider-side generation is immune to your clock, but the runner's clock still matters if anything local also generates

References

  • references/providers.md — per-provider setup, exact endpoints and response shapes, rate limits, token scoping, the Google Authenticator export format, and where Twilio Verify TOTP actually fits.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.