- パブリックツール - 追加の権限がなくても、認証済みのすべてのユーザーがアクセス可能
- ロールベースのアクセス - 特定のロール (
admin、content_editor) に割り当てられたツール - グループメンバーシップ - ユーザーはグループ (managers、marketing) への所属を通じて権限を継承
- 時間制限付きアクセス - 期限が来ると自動的に失効する、期間限定のツールアクセス
- リソース固有の権限 - ツール機能に対するきめ細かな制御 (例:非公開ドキュメントの閲覧)
- Auth0 OAuth 2.0でユーザーを認証する
- Auth0 FGAを使用して、各ユーザーがアクセスできるツールを判定する
- ユーザーの権限に応じてツール一覧を動的に絞り込む
- 自動的に失効する期間限定のアクセス権の付与をサポートする
- ユーザーのロールに応じて異なるデータ (公開ドキュメントと非公開ドキュメント) を提供する
Prerequisites
1. Create or log in to your Auth0 account
1. Create or log in to your Auth0 account
3. Install the Auth0 CLI
3. Install the Auth0 CLI
- Follow the Auth0 CLI installation instructions.
- Log in to your account with the Auth0 CLI:
4. Install jq
4. Install jq
- macOS
- Linux
- Windows
1. FGA CLIをインストールする
1. FGA CLIをインストールする
- Install the FGA CLI:
- macOS
- Linux
- Windows
- Verify the installation:
2. Auth0 FGAまたはOpenFGAをセットアップする
2. Auth0 FGAまたはOpenFGAをセットアップする
- Auth0 FGA: Fully managed service at fga.dev. Best for production use.
- OpenFGA: Self-hosted open-source option. Best for local development and testing.
fga/model.fga) and initial permission tuples (fga/tuples.yaml) that will be imported using the FGA CLI.テナント設定を構成する
1. Promote the connection to a domain-level connection
1. Promote the connection to a domain-level connection
List Your Connection
Choose Your Connections
- For the username-and-password database, look for the connection with the strategy
auth0. - For the Google social connection, look for the connection with the strategy
google-oauth2.
Upgrade the Connection to Domain-Level
YOUR_CONNECTION_ID with the actual ID (e.g., con_XXXXXXXXXXXXXXXX).MCPサーバーを表すAPIを作成する
An MCP server is treated just like any other API in your Auth0 tenant, which means you can use the same access control, scoping, and authorization features. The API (also known as a Resource Server) represents your protected MCP Server. Run the following command to create an API in Auth0:rfc9068_profile_authz is used as the token dialect to include the permissions claim in the access token, which can be useful for the API to check user permissions without making additional calls.
For more details on protecting APIs with Auth0, check our quickstarts.
tool:greetとtool:whoamiの2つのOAuthスコープを使用します。get_datetimeツールはパブリックなためスコープは不要です。一方、get_documentsはFGAを使って認可を行います。FGA ストアをセットアップする
- Auth0 FGA
- OpenFGA (Local)
Create an Auth0 FGA account
Create a store
Generate API credentials
- Navigate to Settings in your store.
- In the Authorized Clients section, click + Create Client.
- Give your client a name and select the following permissions:
- Read/Write model, changes, and assertions - To query authorization decisions
- Write and delete tuples - To import tuples (user permissions)
- Read and query - To import the authorization model
- Click Create.
- Save the credentials shown in the confirmation modal.
Configure environment variables
FGA_API_URL may vary based on your region (e.g., api.eu1.fga.dev for Europe).サンプルアプリ
まず、このクイックスタート用のサンプルアプリをダウンロードまたはクローンしてください。このサンプルには、Auth0 OAuthとAuth0 FGAを統合した、JavaScript/TypeScript製のFastMCP MCPサーバーが含まれています。- サンプルアプリを使用する(推奨)
- GitHubリポジトリをクローンする
パッケージのインストール
必要な依存関係をインストールします。環境ファイルを作成する
From the root of your sample app directory, run the following command to create a new.env file with your Auth0 configuration:
.env file. The variables you need depend on which FGA provider you’re using:
- Auth0 FGA
- OpenFGA (Local)
.env file using the credentials from your Auth0 FGA store:YOUR_STORE_IDwith your store ID from the Auth0 FGA dashboardYOUR_CLIENT_IDwith your client IDYOUR_CLIENT_SECRETwith your client secret- Update
FGA_API_URLif your store is in a different region (e.g.,https://api.eu1.fga.devfor Europe)
.env file should look like this:
- Auth0 FGA
- OpenFGA (Local)
認可モデルについて
The authorization model in this sample demonstrates how Auth0 FGA provides fine-grained access control using Relationship-Based Access Control (ReBAC).Authorization Model Structure
The complete model is defined infga/model.fga:
1. Public Tools
1. Public Tools
user:* means any authenticated user can use the get_datetime tool.2. Role-Based Access
2. Role-Based Access
admin role automatically gain access to these tools.3. Group Membership
3. Group Membership
managers group, they automatically inherit all permissions of the admin role, including access to all tools.4. Temporal Access
4. Temporal Access
5. Resource-Specific Permissions
5. Resource-Specific Permissions
get_documents tool checks this permission separately to determine whether to return private documents. This allows the same tool to provide different data based on user permissions.Example:- Admin role: Sees all documents (public + private)
- Content editor role: Sees only public documents
How Authorization Works
When a user connects to the MCP server:- The server authenticates the user with Auth0 (validates JWT token)
- The server queries FGA to get all tools the user can access:
- Checks
can_userelation for each tool - Evaluates group memberships, role assignments, and temporal conditions
- Checks
- The server returns only authorized tools to the MCP client
- When the user calls a tool like
get_documents, the server checkscan_view_private_documentsto determine what data to return
認可モデルとタプルをインポートする
このサンプルには、完全な認可モデルと初期の権限タプルが含まれており、次の内容が定義されています。- すべてのユーザーに対する
get_datetimeへのパブリックアクセス - ロールの割り当て (
admin、content_editor) - グループとロールのマッピング (
managers→admin、marketing→content_editor) - 各ロールのツールアクセス権限
認可モデルを確認する
fga/model.fga で定義されています。ユーザー、グループ、ロール、ツールの型に加え、時間制限付きアクセスの条件が含まれています。初期タプルは fga/tuples.yaml で定義されており、ベースとなる権限を設定します。モデルとタプルをインポートする
- 新しい FGA ストアを作成する (OpenFGA をローカルで使用している場合)
fga/model.fgaの認可モデルをアップロードするfga/tuples.yamlの初期タプルをインポートするfga/store.fga.yamlで定義されたテストを実行し、設定を検証する
.env ファイルに FGA_STORE_ID として追加してください。Auth0 FGA で既存のストアを使用している場合は、新しいモデルとタプルでストアが更新されます。インポートを確認する
MCPサーバーを実行する
MCPサーバーを起動します。.env ファイルで指定したポート) で起動します。コンソールに、次の内容を示す出力が表示されるはずです。
- サーバーが正常に起動したこと
- FGA クライアントが初期化されたこと
- サーバーが
http://localhost:3001/mcpで接続を待ち受けていること
ユーザー権限を管理する
The sample application includes helper scripts in thefga/ directory to make permission management easier. These scripts use the FGA CLI to add or remove authorization tuples dynamically.
Available Scripts
Add User to Group
Add User to Group
managers- Assigned toadminrole (all tools + private documents)marketing- Assigned tocontent_editorrole (all tools, public documents only)
Remove User from Group
Remove User from Group
Grant Temporal Access
Grant Temporal Access
s for seconds, m for minutes, h for hours).Available tools: greet, whoami, get_documentsget_datetime don’t need temporal access grants since they’re already accessible to all authenticated users.Reset Tuples
Reset Tuples
fga/tuples.yaml.Usage:fga/tuples.yaml. Useful for returning to a clean state during testing.Testing Permission Changes
After running any of these scripts, you need to reload the tools:- for MCP inspector: click ‘Clear’ in the MCP inspector tools panel and then ‘List Tools’
- for other MCP clients: you might need to reconnect the MCP Client to see the updated tool list.
Testing your MCP server
Now that your MCP server is up and running, you can test it by using tools like MCP Inspector.Learn how to test your Auth0-powered MCP server
認可シナリオをテストする
次に、さまざまな認可シナリオをテストして、FGAがツールへのアクセスをどのように制御するかを確認します。サーバーへの接続には、MCP InspectorなどのMCPクライアントが必要です。基本アクセスをテストする
get_datetimeこのことから、ロールやグループが割り当てられていない場合、認証済みユーザーはパブリックツールにしかアクセスできないことがわかります。managersグループで管理者アクセスを付与する
YOUR_EMAILは、認証に使用するメールアドレスに置き換えてください。MCPクライアントで再接続し、すべてのツールが表示されることを確認します。想定されるツール:get_datetime、greet、whoami、get_documentsget_documentsツールを呼び出し、レスポンスにパブリックとプライベートの両方のドキュメントが含まれていることを確認します。これは、管理者ロールに基づくリソース固有の権限が機能していることを示しています。コンテンツ編集者ロールをテストする
get_datetime、greet、whoami、get_documentsget_documentsツールを呼び出し、今度はパブリックドキュメントのみが表示される (プライベートドキュメントは表示されない) ことを確認します。このように、同じツールでもユーザーのロールに応じて異なるデータを返すことができます。主な違い:コンテンツ編集者は管理者と同じツールにアクセスできますが、can_view_private_documents権限は持っていません。時間制限付きアクセスをテストする
greetツールへの20秒間のアクセスが付与されます。MCPクライアントですぐに再接続します。想定されるツール:get_datetime、greetgreetツールを呼び出して、動作することを確認します。25秒待ってからもう一度再接続します。想定されるツール:get_datetime (のみ)greetツールは表示されなくなっているはずです。このように、時間制限付きアクセスはクリーンアップ作業なしで自動的に失効します。次のステップ
- よりシンプルなスコープベースのアプローチについては、MCPサーバーの認可を参照してください
- 認可モデルの設計について詳しくは、Auth0 FGA のドキュメントをご覧ください
- 高度なモデリングパターンやベストプラクティスについては、OpenFGAのドキュメントを参照してください
- MCP Inspector を使用して MCPサーバーをテストする方法をご確認ください