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

# 委任管理：アクセスフック

> 委任管理拡張機能を持つアクセスフックを使用する方法について説明します。

フィルターフックはフィルタリングロジックのみを適用するため、現在のユーザー（または管理者の役割を果たしている人物）が特定のユーザーへのアクセス権を持っているかどうかを判定するには、2番目のロジック層が必要になります。

フィルターフックの詳細については、「[委任管理：フィルターフック](/docs/ja-jp/customize/extensions/delegated-administration-extension/delegated-administration-hooks/delegated-administration-filter-hook)」をお読みください。

**［Access Hook（アクセスフック）** では、現在のユーザーが特定のユーザーを読み取り、削除、ブロック、ブロック解除、または更新することができるかどうかを判定できます。

## フックコントラクト

* **ctx** ：コンテキストオブジェクト。

  * **payload** ：ペイロードオブジェクト。

    * **action** ：実行されている現在のアクション（ **delete:user** など）。
    * **user** ：アクションが実行されているユーザー。
* **callback(error)** ：アクセスが拒否された場合にエラーを返すことができるコールバック。

## 使用例

財務部の管理を担うケリーがアクセスできるのは、部署内のユーザーのみに限られるべきです。

```javascript lines theme={null}
function(ctx, callback) {
  if (ctx.payload.action === 'delete:user') {
    return callback(new Error('You are not allowed to delete users.'));
  }

  // Get the department from the current user's metadata.
  var department = ctx.request.user.app_metadata && ctx.request.user.app_metadata.department;
  if (!department || !department.length) {
    return callback(new Error('The current user is not part of any department.'));
  }

  // The IT department can access all users.
  if (department === 'IT') {
    return callback();
  }

  ctx.log('Verifying access:', ctx.payload.user.app_metadata.department, department);

  if (!ctx.payload.user.app_metadata.department || ctx.payload.user.app_metadata.department !== department) {
    return callback(new Error('You can only access users within your own department.'));
  }

  return callback();
}
```

## 注記

このフックが構成されていないと、現在のユーザーはすべてのユーザーにアクセスすることができます。

フックは以下のアクション名（ **ctx.payload.action** の値として使用して設定）をサポートします。

* read:user
* delete:user
* reset:password
* change:password
* change:username
* change:email
* read:devices
* read:logs
* remove:multifactor-provider
* block:user
* unblock:user
* send:verification-email

## もっと詳しく

* [委任管理：フィルターフック](/docs/ja-jp/customize/extensions/delegated-administration-extension/delegated-administration-hooks/delegated-administration-filter-hook)
* [委任管理：メンバーシップクエリフック](/docs/ja-jp/customize/extensions/delegated-administration-extension/delegated-administration-hooks/delegated-administration-memberships-query-hook)
* [委任管理：クエリ設定フック](/docs/ja-jp/customize/extensions/delegated-administration-extension/delegated-administration-hooks/delegated-administration-settings-query-hook)
* [委任管理：書き込みフック](/docs/ja-jp/customize/extensions/delegated-administration-extension/delegated-administration-hooks/delegated-administration-write-hook)
