api-jwt-authenticator
JWT認証でFastAPI APIを安全に保護する
FastAPI APIには、エンドポイントとユーザーデータを保護するための安全な認証が必要です。このスキルは、JWTトークン検証、ユーザーアイデンティティ確認、REST API向けのロールベースアクセス制御の実装ガイダンスを提供します。
スキルの ZIP をダウンロード
Claudeでアップロード
設定 → 機能 → スキル → スキルをアップロード に移動
オンにして使い始める
エージェントが読めるリソース
AI エージェント、クローラー、スクリプトがページ全体ではなく整理されたコンテキストを必要とする場合は、これらのリンクを使ってください。
テストする
「api-jwt-authenticator」を使用しています。 FastAPIのユーザープロファイルエンドポイントにJWT認証を追加する
期待される結果:
- AuthorizationヘッダーからJWTトークンを抽出
- 秘密鍵でトークン署名を検証
- トークン有効期限を検証(期限切れでない)
- トークンペイロードからユーザーIDを抽出
- 認証済みリクエストにユーザープロファイルを返す
- 無効なトークンには401 Unauthorizedを返す
「api-jwt-authenticator」を使用しています。 ロールベースアクセスを使った管理者専用エンドポイントを作成する
期待される結果:
- JWTトークンペイロードからユーザーロールを抽出
- 必要な「admin」権限とロールを比較
- 管理者ユーザーに機密エンドポイントへのアクセスを許可
- 管理者以外のユーザーには403 Forbiddenを返す
- セキュリティ監視のために認証監査を記録
セキュリティ監査
低リスクStatic analysis flagged Markdown backticks, JWT terminology, and HTTP authentication documentation as suspicious patterns. Review found no executable code, shell invocation, prompt injection, malware behavior, or data exfiltration in SKILL.md. The skill is a conceptual security guide and is safe to publish with low residual risk.
Static false positives ignored (3)
These static matches were dismissed by semantic review or matched schema-only tokens, so they are shown for transparency but do not drive the quality score.
品質スコア
作成できるもの
APIエンドポイントの保護
JWTトークン検証とユーザーアイデンティティ確認により、認証済みユーザーアクセスが必要なFastAPIエンドポイントを保護します。
アクセス制御の実装
ロールベースアクセス制御ポリシーを適用し、ユーザーが権限のあるリソースのみを閲覧できるようにします。
認証システムの設計
適切なセキュリティ考慮のもと、JWTトークンを用いたマイクロサービス向けのステートレス認証パターンを設計します。
これらのプロンプトを試す
Use the API JWT Authenticator skill to add JWT authentication to a FastAPI endpoint. Extract the Bearer token from the Authorization header, validate the signature using a secret key, verify expiration, and return user info or 401 error.
Apply the JWT Authenticator pattern to ensure users can only access their own resources. Extract user_id from token payload, compare with resource owner, and return 403 if they do not match.
Implement role-based access control using the JWT Authenticator skill. Define admin, moderator, and user roles in token claims. Create dependencies that verify user role before allowing endpoint access.
Design a complete JWT authentication system for FastAPI following best practices from the API JWT Authenticator skill. Include token generation endpoint, protected routes, error handling, and production security considerations.
ベストプラクティス
- 本番環境では常にHTTPSを使用し、送信中のトークン盗聴を防ぐ
- 秘密鍵は環境変数や安全なボールトに保存し、ソースコードに置かない
- 侵害されたトークンの露出期間を制限するため、適切なトークン有効期限を設定する
回避
- JWTトークンをURLやサーバーログにそのまま露出しない。トークン盗難につながるため
- JWTペイロードに機密情報を保存しない。トークンは誰でもデコードできるため
- 開発やテスト環境でもトークン署名検証を省略しない