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

> Rules、Hooks、および以前のバージョンの Actions から Actions へ移行する方法を学びます。

# Actions ベータ版から正式版への移行

カスタムコードを通じた Auth0 の拡張性に関する長期的なビジョンの一環として、Actions のベータ期間中に導入したプログラミングモデルを洗練し、簡素化しました。今後は、すべての Trigger 間で、より一貫性があり予測しやすい方法で Actions を作成できるようになります。イベントデータは [Auth0 Management API](https://auth0.com/docs/api/management/v2) および Auth0 プラットフォームの他の側面と、より緊密に整合するようになりました。カスタムコードによってトランザクションの動作を変更する場合は、常に新しい `api` 引数のメソッドを呼び出すことで行います。

[一般提供 (GA)](/docs/ja-JP/troubleshoot/product-lifecycle/product-release-stages#general-availability) 以前の期間に作成された Action を移行するには、通常、次の手順を実施します。

1. [重大な変更点](#breaking-changes) セクションで説明しているとおりに、名前変更や場所の変更が行われたイベントプロパティへの参照を調整します。
2. 望ましい副作用を記述したオブジェクトを組み立てて返す代わりに、[副作用の実行](#performing-side-effects) セクションで説明しているとおり、関連する `api` メソッドを呼び出すようにカスタムコードを更新します。
3. リダイレクトコールバックを処理する必要がある Actions では、新たに公開された専用関数を使用します。`event.protocol === 'redirect-callback'` に依存するコードを使用していた場合は、[Redirect with Actions](/docs/ja-JP/customize/actions/explore-triggers/signup-and-login-triggers/login-trigger/redirect-with-actions) のページを確認してください。

<div id="breaking-changes">
  ## 破壊的変更
</div>

<div id="query-and-body-parameters">
  ### クエリおよびボディパラメーター
</div>

クエリおよびボディパラメーターには、`event.request.query` と `event.request.body` オブジェクトを使用して直接アクセスできます。これらは、認可が `GET` リクエストまたは `POST` リクエストのいずれで開始されたかに関わらず利用できます。認可リクエストの一部として送信される多くのプロトコル固有のクエリまたはボディパラメーターは、現在では `event.transaction` オブジェクト上のトップレベルの値としても利用できます。ユースケースがサポートされていない場合を除き、`event.request.query` および `event.request.body` ではなく `event.transaction` を使用することを推奨します。これらの変更の対応関係を以下に示します。

<table class="table">
  <thead>
    <tr>
      <th>GA 前のプロパティ</th>
      <th>GA のプロパティ</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td><code>event.actor.ip</code></td>
      <td><code>event.request.ip</code></td>
    </tr>

    <tr>
      <td><code>event.actor.hostname</code></td>
      <td><code>event.request.hostname</code></td>
    </tr>

    <tr>
      <td><code>event.actor.geoIp</code></td>
      <td><code>event.request.geoip</code></td>
    </tr>

    <tr>
      <td><code>event.actor.language</code></td>
      <td><code>event.request.language</code></td>
    </tr>

    <tr>
      <td><code>event.actor.method</code></td>
      <td><code>event.request.method</code></td>
    </tr>

    <tr>
      <td><code>event.actor.userAgent</code></td>
      <td><code>event.request.user\_agent</code></td>
    </tr>

    <tr>
      <td><code>event.actor.body</code></td>
      <td><code>event.request.body</code></td>
    </tr>

    <tr>
      <td><code>event.actor.query</code></td>
      <td><code>event.request.query</code></td>
    </tr>

    <tr>
      <td><code>event.actor.query.audience</code></td>
      <td><code>event.resource\_server.identifier</code></td>
    </tr>

    <tr>
      <td><code>event.actor.query.scope</code></td>
      <td><code>event.transaction.requested\_scopes</code></td>
    </tr>

    <tr>
      <td><code>event.actor.query.acr\_values</code></td>
      <td><code>event.transaction.acr\_values</code></td>
    </tr>

    <tr>
      <td><code>event.actor.query.ui\_locales</code></td>
      <td><code>event.transaction.ui\_locales</code></td>
    </tr>

    <tr>
      <td><code>event.protocol</code></td>
      <td><code>event.transaction.protocol</code></td>
    </tr>

    <tr>
      <td><code>context.secrets</code></td>
      <td><code>event.secrets</code></td>
    </tr>
  </tbody>
</table>

<div id="user-profile-properties">
  ### ユーザー プロファイルのプロパティ
</div>

全般的に、`event.user` オブジェクトのプロパティは、[Auth0 ユーザープロファイル構造](/docs/ja-JP/manage-users/user-accounts/user-profiles/user-profile-structure) に合わせるために、キャメルケースからスネークケースへ変更されています。例えば、`event.user.appMetadata` は `event.user.app_metadata` に変更されました。

<div id="performing-side-effects">
  ### 副作用の実行
</div>

GA 前の post-login トリガーのバージョンでは、Action からオブジェクトを返すことで副作用を実行していました。Actions GA では、これらの変更をカプセル化し、エディタ内でより良い型ヒントとインラインドキュメントを提供するために、`api` オブジェクトが用意されています。

<div id="update-user-user_metadata">
  #### ユーザーの user\_metadata を更新する
</div>

GA 前トリガー:

```js lines theme={null}
async function myFunction(event, context) {
  return {
    user: {
      userMetadata: {
        myParam: "foo"
      }
    }
  };
}
```

GA トリガー:

```js lines theme={null}
async function onExecutePostLogin(event, api) {
  api.user.setUserMetadata('myParam', 'foo');
}
```

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  このメソッドはコールバック内で使用すべきではありません。このメソッドを呼び出しても、メタデータは即座には更新されないためです。その代わりに、同じフロー内の複数の Actions で、このメソッドを複数回呼び出すことができます（1 つの Action で設定されたメタデータは一時オブジェクトに適用され、その後の Actions からも利用可能になります）。実行エンジンはそれらの変更を集約し、フローが完了する前にメタデータを一括で更新します。
</Callout>

<div id="update-user-app_metadata">
  #### ユーザーの app\_metadata の更新
</div>

GA 前トリガー:

```js lines theme={null}
async function myFunction(event, context) {
  return {
    user: {
      appMetadata: {
        myParam: "foo"
      }
    }
  };
}
```

GA トリガー：

```js lines theme={null}
async function onExecutePostLogin(event, api) {
  api.user.setAppMetadata('myParam', 'foo');
}
```

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  コールバック内ではこのメソッドを使用しないでください。このメソッドを呼び出しても、メタデータは即座には更新されません。その代わりに、同じフロー内の複数の Actions でこのメソッドを複数回呼び出すことができます（ある Action で設定されたメタデータは一時オブジェクトに適用されるため、後続の Actions でも利用できます）。エンジンはこれらの変更を集約し、フローが完了する前にメタデータをまとめて更新します。
</Callout>

<div id="deny-a-login">
  ### ログインを拒否する
</div>

GA 前のトリガー:

```js lines theme={null}
async function myFunction(event, context) {
  throw new Error("Access denied.");
}
```

GA のトリガー:

```js lines theme={null}
async function onExecutePostLogin(event, api) {
  api.access.deny("Access denied.");
}
```

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  Error をスローしてもログインは拒否されますが、`api.access.deny` を呼び出すことが推奨されます。
</Callout>

<div id="add-custom-claims-to-the-access-token">
  ### アクセストークンにカスタムクレームを追加する
</div>

GA 前トリガー:

```js lines theme={null}
async function myFunc(event, context) {
  return {
    accessToken: {
      customClaims: {
        'https://example.com/custom/claim': 'Custom claim value',
      }
    }
  };
}
```

GA トリガー:

```js lines theme={null}
async function myFunc(event, api) {
  api.accessToken.setCustomClaim('https://example.com/custom/claim', 'Custom claim value');
}
```

<div id="add-custom-claims-to-the-id-token">
  ### IDトークンにカスタムクレームを追加する
</div>

GA前トリガー：

```js lines theme={null}
async function myFunc(event, context) {
  return {
    idToken: {
      customClaims: {
        'https://example.com/custom/claim': 'Custom claim value',
      }
    }
  };
}
```

GA トリガー:

```js lines theme={null}
async function myFunc(event, api) {
  api.idToken.setCustomClaim('https://example.com/custom/claim', 'Custom claim value');
}
```

<div id="dynamically-enable-multi-factor-authentication">
  ### 多要素認証を動的に有効にする
</div>

GA 前トリガー:

```js lines theme={null}
async function myFunction(event, context) {
  return {
    command: {
      type: "multifactor",
      provider: "any"
    }
  };
}
```

GA トリガー:

```js lines theme={null}
async function onExecutePostLogin(event, api) {
  api.multifactor.enable("duo");
}
```

<div id="redirect-the-user">
  ### ユーザーをリダイレクトする
</div>

GA 前のトリガー:

```js lines theme={null}
async function myFunction(event, context) {
  return {
    command: {
      type: "redirect",
      url: "https://my-app.example.com"
    }
  };
}
```

GA トリガー:

```js lines theme={null}
async function onExecutePostLogin(event, api) {
  api.redirect.sendUserTo("https://my-app.example.com");
}
```

パラメータが安全に送信され、リプレイ攻撃を回避できるようにするため、リダイレクト経由でデータを渡す方法は Actions の GA に伴い大きく変更されました。詳細については、[Redirect with Actions](/docs/ja-JP/customize/actions/explore-triggers/signup-and-login-triggers/login-trigger/redirect-with-actions) を参照してください。

<div id="manipulate-scopes">
  ### スコープの操作
</div>

Actions のベータ期間中は、ID トークンおよび <Tooltip tip="アクセストークン: 不透明な文字列または JWT の形式で表される認可情報で、API にアクセスするために使用されます。" cta="用語集を表示" href="/docs/ja-JP/glossary?term=Access+Token">アクセストークン</Tooltip> のスコープを直接操作できる機能を試験的に提供していましたが、Actions GA ではこの機能はサポートしていません。
