> ## Documentation Index
> Fetch the complete documentation index at: https://translations.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Auth0 Model Context Protocol (MCP) Server を使用して、API の認可フローを効率化します。

# Auth0 Model Context Protocol (MCP) Server で API 認可フローを効率化

<Card title="概要">
  以下について学びます。

  1. 現在の API 設定を確認する
  2. 適切なスコープを持つ新しい API 定義を作成する
  3. Auth0 Actions を使用してカスタム認可ロジックを実装する
  4. 認可システムをデプロイしてテストする
  5. 認可ルールを監視し、改善する
</Card>

<Card title="開始前">
  1. 管理者権限を持つ Auth0 アカウントを作成する
  2. Auth0 MCP Server をインストールし、Claude Desktop と連携する
</Card>

[Auth0 MCP Server](/ja/docs/get-started/auth0-mcp-server) との自然言語でのやり取りを通じて、包括的な API 認可システムをすばやくセットアップして管理できます。Model Context Protocol を介して Auth0 と対話できる [Claude](https://claude.ai/) の機能を活用すれば、複雑な認可パターンも数時間ではなく数分で実装できます。

<div id="step-1-explore-current-api-configuration">
  ### ステップ 1: 現在の API 設定を確認する
</div>

新しい API を作成する前に、テナントにすでにどのような設定があるのかを把握しておくことが重要です。Auth0 MCP Server を使えば、自然言語でこの情報をすばやく取得できます。

Claude に依頼します:

```bash wrap lines theme={null}
Show me all the resource servers (APIs) currently configured in my Auth0 tenant.
```

Claude は `auth0_list_resource_servers` ツールを使用して、既存の API を取得し、一覧表示します。これにより、<Tooltip tip="Auth0 Dashboard: サービスを設定するための Auth0 の主要製品です。" cta="用語集を表示" href="/ja/docs/glossary?term=Auth0+dashboard">Auth0 Dashboard</Tooltip> を開いて確認しなくても、API の全体像をすばやく把握できます。

<div id="step-2-create-new-api-definitions">
  ### ステップ 2: 新しい API 定義を作成する
</div>

現在の設定を把握できたので、マイクロサービス アーキテクチャ向けの新しい API を作成できます。各 API を Dashboard で個別に設定する代わりに、まとめて一度に定義できます。

Claude に依頼します:

```bash lines theme={null}
I need to create three new APIs for our microservices:
1. An inventory API with read and write scopes
2. An orders API with read and write scopes
3. A customers API with read, write, and admin scopes

Each API should enforce scope validation.
```

Claude は、これらの API を設定するために `auth0_create_resource_server` ツールを複数回使用します。

<div id="step-3-implement-authorization-logic">
  ### ステップ 3: 認可ロジックを実装する
</div>

API を定義したら、カスタムの認可ロジックを実装する必要があります。Auth0 MCP Server を使うと、ビジネスルールを自然言語で記述でき、Claude が適切な Auth0 [Actions](/ja/docs/customize/actions) のコードを生成します。

Claude に次のように依頼します:

```bash lines theme={null}
以下の認可ルールを適用するActionを作成してください：
1. リクエスト元のアプリケーションが、アクセス対象のAPIに対して適切なスコープを持っていることを確認する。
2. customers APIに対して、adminスコープを使用するリクエストは、社内のIPレンジ（10.0.0.0/8および172.16.0.0/12）からのみ許可する。
3. 監査目的で、すべての認可判断をログに記録する。
```

Claude は `auth0_create_action` ツールを使用して、適切なコードを持つ Action を生成・作成します。

<div id="step-4-deploy-the-authorization-action">
  ### ステップ4: 認可 Action をデプロイする
</div>

Action コードの内容に問題がなければ、簡単な指示で本番環境にデプロイできます。

Claude に依頼します:

```bash lines theme={null}
Deploy this action to run during the token issuance process.
```

Claude は、`auth0_deploy_action` ツールを使用して Action をデプロイします。

<div id="step-5-configure-client-applications">
  ### ステップ 5: クライアントアプリケーションを設定する
</div>

次に、適切な API に正しいスコープでアクセスできるよう、クライアントアプリケーションを設定します。

Claude に質問:

```bash wrap lines theme={null}
Create an 'inventory-manager' application on my Auth0 tenant and update the app to access the inventory and orders APIs with read and write permissions, but not the customers API.
```

Claude はまず `auth0_get_application` を使って現在の設定を取得し、次に `auth0_update_application` を使ってそれを更新します。

<div id="step-6-verify-configuration">
  ### ステップ 6: 設定を確認する
</div>

認可システムが正しく動作していることを確認するには、認可に関する問題がないかログを確認します。

Claude に依頼します:

```bash wrap lines theme={null}
Check the logs for any failed API access attempts in the last hour. Focus on authorization failures.
```

Claude は `auth0_list_logs` を使用して、関連するログエントリを検索します。

<div id="step-7-refine-the-authorization-rules">
  ### ステップ 7: 認可ルールを調整する
</div>

ログ分析の結果に基づいて、認可ルールの調整が必要になる場合があります。たとえば、追加の IP 範囲からのアクセスを許可する必要があるかもしれません。

Claude に依頼します:

```bash wrap lines theme={null}
Update the authorization action to also allow requests from our development VPN range 192.168.100.0/24.
```

Claude は `auth0_get_action` を使用して現在の Action コードを取得し、続いて `auth0_update_action` を使用してそれを変更します。

最後に、Claude は `auth0_deploy_action` を使用して更新後の Action をデプロイします。

<div id="conclusion">
  ### まとめ
</div>

Claude と Auth0 MCP Server を使用することで、次のような包括的な API 認可システムを実装できました。

* 適切なスコープを持つ複数の API 定義を作成する
* IP ベースの制限を用いたカスタム認可ロジックを実装する
* 特定の API にアクセスできるようクライアントアプリケーションを設定する
* 認可ルールを監視して継続的に改善する

この自然言語によるアプローチでは、時間を節約できるだけでなく、Auth0 の Actions システムやログクエリ構文に関する深い専門知識がなくても、セキュリティのベストプラクティスを実装できます。

<div id="next-steps">
  ## 次のステップ
</div>

* ユーザー属性に基づく追加の認可ルールを実装する
* セキュリティ分析に向けて、ログを定期的に監視する
* API の利用パターンを可視化するカスタムダッシュボードを作成する
