> ## 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.

> Rules 内から Management API を使用する方法を説明します。

# Rules 内から Management API を使用する

<Warning>
  Rules と Hooks のサポート終了 (EOL) 日は**2026年11月18日**です。また、**2023年10月16日**以降に作成された新しいテナントでは、これらはすでに利用できません。Hooks が有効な既存のテナントでは、サポート終了日まで Hooks の製品アクセスが維持されます。

  Auth0 を拡張するには、Actions の使用を強くお勧めします。Actions では、豊富な型情報、インラインドキュメント、公開 `npm` パッケージを利用できるほか、外部統合にも接続できるため、拡張機能の開発体験全体を向上させることができます。Actions で提供される機能の詳細については、[Understand How Auth0 Actions Work](/ja/docs/customize/actions/actions-overview) を参照してください。

  移行を支援するために、[Rules から Actions への移行](/ja/docs/customize/actions/migrate/migrate-from-rules-to-actions) と [Hooks から Actions への移行](/ja/docs/customize/actions/migrate/migrate-from-hooks-to-actions) のガイドを用意しています。また、機能比較、[Actions のデモ](https://www.youtube.com/watch?v=UesFSY1klrI)、その他移行に役立つリソースをまとめた専用ページ [Move to Actions](https://auth0.com/platform/extensibility/movetoactions) も提供しています。

  Rules と Hooks の非推奨化の詳細については、ブログ記事 [Preparing for Rules and Hooks End of Life](https://auth0.com/blog/preparing-for-rules-and-hooks-end-of-life/) を参照してください。
</Warning>

作成した任意の [Auth0 Rule](/ja/docs/customize/rules) 内では、`auth0` オブジェクトを使用して、ユーザーの `app_metadata` または `user_metadata` を更新できます。`auth0` は、[node-auth0](https://github.com/auth0/node-auth0) Node.js クライアントライブラリで定義された、特別に制限された `ManagementClient` のインスタンスであり、[Auth0 Management API](https://auth0.com/docs/api/management/v2) への限定的なアクセスを提供します。

Rules 内から追加の <Tooltip tip="Management API: お客様が管理タスクを実行できるようにする製品です。" cta="用語集を表示" href="/ja/docs/glossary?term=Management+API">Management API</Tooltip> エンドポイントにアクセスするには、別バージョンのライブラリを使用する必要があります。

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  `auth0.accessToken` から利用できる Management API 用のアクセストークンは、`read:users` と `update:users` のスコープに制限されています。より広い範囲のスコープが必要な場合は、Client Credentials Flow を使用してトークンをリクエストできます。詳細については、[Get Management API Access Tokens for Production](/ja/docs/secure/tokens/access-tokens/management-api-access-tokens/get-management-api-access-tokens-for-production) を参照してください。
</Callout>

<div id="access-a-newer-version-of-the-library">
  ## ライブラリの新しいバージョンを使用する
</div>

ライブラリの特定のバージョンを指定して require することで、Auth0 Node.js クライアントライブラリの新しいバージョンを読み込めます。最新のバージョン情報については、GitHub の [Auth0 Node repository](https://github.com/auth0/node-auth0) を確認してください。

この例では、ライブラリのバージョン `2.9.1` を読み込んでから、ユーザー一覧を取得し、その内容をコンソールに出力します ([Actions Real-time Logs](/ja/docs/customize/actions/actions-real-time-logs) で確認できます) 。

<Warning>
  Rules 内から[ユーザーを検索する](/ja/docs/manage-users/user-search/user-search-best-practices)と、ログインのパフォーマンスに影響する可能性があるため、推奨されません。
</Warning>

```javascript lines theme={null}
function (user, context, callback) {
  var ManagementClient = require('auth0@2.9.1').ManagementClient;
  var management = new ManagementClient({
    token: auth0.accessToken,
    domain: auth0.domain
  });

  management.getUsers(function (err, users) {
    console.log(users);
    callback(null, user, context);
  });
}
```

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  必須として設定できる利用可能なライブラリの絞り込み一覧については、[利用可能なライブラリのバージョン](https://auth0-extensions.github.io/canirequire/#auth0)を確認してください。
</Callout>
