メインコンテンツへスキップ
Filter Hook はフィルタリング ロジックのみを適用するため、現在のユーザー (または管理者として操作しているユーザー) が特定のユーザーにアクセスできるかどうかを判断するには、別のロジック層が必要です。 Filter Hook の詳細については、Delegated Administration: Filter Hookを参照してください。 Access Hook を使用すると、現在のユーザーに特定のユーザーの読み取り、削除、ブロック、ブロック解除、更新を許可するかどうかを判断できます。

Hook のコントラクト

  • ctx: コンテキストオブジェクト。
    • payload: ペイロードオブジェクト。
      • action: 現在実行されているアクション (例: delete:user) 。
      • user: アクションの実行対象となるユーザー。
  • callback(error): アクセスが拒否された場合にエラーを返せるコールバック。

使用例

Kelly は財務部門を管理しており、自分の部門に所属するユーザーのみにアクセスできるようにする必要があります。
function(ctx, callback) {
  if (ctx.payload.action === 'delete:user') {
    return callback(new Error('You are not allowed to delete users.'));
  }

  // 現在のユーザーのメタデータから部署を取得します。
  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.'));
  }

  // IT部門はすべてのユーザーにアクセスできます。
  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();
}

注記

このHookが設定されていない場合、現在のユーザーはすべてのユーザーにアクセスできます。 Hook は次のアクション名をサポートしています (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

詳細情報