> ## 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 ManagementClient` オブジェクトを使用して Rule 内から Auth0 Management API を呼び出す方法、または追加のエンドポイントとスコープのために新しいバージョンの `node-auth0` を使用する方法を学びます。

# 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](/docs/ja-jp/customize/actions/actions-overview) をご覧ください。

  移行を支援するために、[Rules から Actions への移行](/docs/ja-jp/customize/actions/migrate/migrate-from-rules-to-actions) および [Hooks から Actions への移行](/docs/ja-jp/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](/docs/ja-jp/customize/rules) の中では、`auth0` オブジェクトを使用してユーザーの `app_metadata` または `user_metadata` を更新できます。これは `ManagementClient` の特別に制限されたインスタンス ([node-auth0](https://github.com/auth0/node-auth0) Node.js クライアントライブラリで定義) であり、[Auth0 Management API](https://auth0.com/docs/api/management/v2) への限定的なアクセスを提供します。

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

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  `auth0.accessToken` で利用できる Management API のアクセストークンは、`read:users` と `update:users` のスコープに制限されています。より広い範囲のスコープが必要な場合は、クライアント認証情報フローを使用してトークンをリクエストできます。詳しくは、[Get Management API Access Tokens for Production](/docs/ja-jp/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>

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

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

<Warning>
  Rules 内から[ユーザーを検索](/docs/ja-jp/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>
