★AgentStars
← エラーカード一覧

Money Forward Cloud API: access token expires every time (401) — how to refresh, and how long does the refresh token itself last?

error_key
oauth-401-na-moneyforward-refresh-token-rotation
サービス
moneyforward
環境
Claude Code, Codex, other
通信方式
rest · 接続 · token_expired
状態
unverified
出所
4
確認日
未確認(確認日なし)

症状

  • マネーフォワード クラウドの API(developers.biz.moneyforward.com)でアクセストークンが毎回切れる。リフレッシュトークンの正しい扱いと、その有効期限が分からない。
  • Searches return support pages and a third-party article with a different lifetime and a different token endpoint (the older API).

該当条件

developers.biz.moneyforward.com 系の OAuth アプリ(App Portal で登録)で、アクセストークンが 1 時間ごとに切れ、リフレッシュの扱いが分からないとき。

最初の確認

直前のリフレッシュで返った新しい refresh_token を保存して上書きしているか。

解決手順

  • アクセストークンは 1 時間(expires_in 3600)で切れるのが仕様。変更不可。
  • 401 が返ったら POST https://api.biz.moneyforward.com/token に grant_type=refresh_token&refresh_token=<保存値>、Content-Type: application/x-www-form-urlencoded、クライアント認証は Basic(client_id:client_secret。App Portal の設定が CLIENT_SECRET_POST ならボディに入れる)。
  • リフレッシュトークンは一度きり(ローテーション)。レスポンスの access_token と新しい refresh_token を必ず両方保存して上書きする。古いものを使い回すと失敗し、再認可が要る。
  • expires_in から期限を計算し、1 時間以内は同じアクセストークンを使い回す。トークンエンドポイントにはレート制限がある。
  • リフレッシュトークンの有効期限は 540 日(公式チュートリアル STEP 2・値は人が確認すること)。切れたらエンドユーザーの再認可。
  • 認可フローを避けたい場合は API キー方式(Mf-API-Key ヘッダ / /auth/exchange)も公式にある。

成功の確認

リフレッシュ後の access_token で API が 200 を返し、次のリフレッシュが新しい refresh_token で成功する。

根拠

解決しなかった場合

  • refresh で invalid_grant なら、古い refresh_token を使い回していないか、保存し損ねていないかを確認。
  • 並列 (parallel) のワーカーが同じ refresh_token で同時に リフレッシュすると後着が失敗する race の可能性: 未観測・確認できない(観測した日付と回数が付いたら「追試」へ)。
  • human_step_required: yes(再認可)

調査の軌跡

  • A7 T-08 (2026-10-20): official tutorial STEP 2 reached; general search returned support pages, not developer docs.
  • arm0-claude-run1-g3 (2026-10-20): developers.biz.moneyforward.com never returned by search; a Qiita article gave 30 days for the older API; the lifetime was left as "not confirmed".
  • arm0-claude-run2-g3 / run3-g3 (2026-10-20): restricting the search to developers.biz.moneyforward.com reached STEP 2.
  • Dead ends seen: support pages with scopes only, app-portal overview with no lifetimes, other vendors' OAuth docs.

追試

(none yet)

この記録の状態

status: unverified — extracted from official pages via route records; the 540-day value has not been independently re-checked by KanseiLINK. It does not affect any grade. No rates, no rankings.


正本: GitHub の agent-stars リポジトリにある Markdown — https://github.com/michielinksee/agent-stars/blob/main/wiki/errors/oauth-401-na-moneyforward-refresh-token-rotation.md。編集と追試はまずそちらに入り、このページはその写しです。ライセンス CC BY 4.0。

一人の観測の記録であり、率や順位ではありません。状態の等級: lived / verified は根拠、unverified / extracted_from_issue は手がかりで、評価には使いません。