Actionsのベータから最終版への移行

カスタムコードを通したAuth0の拡張性の長期的ビジョンの一環として、弊社は、Actionsのベータ期間中に紹介したプログラミングモデルを洗練させ、簡素化させてきました。Actionsの作成は、トリガー全体で一貫性のある推測可能な方法で行われるようになります。イベントデータは、Auth0 Management APIおよびAuth0プラットフォームの他のファセットとより密接に連携するようになりました。カスタムコードを介したトランザクションの動作の変更は、新しいapi引数のメソッドを呼び出すことで、常に発生します。

一般提供(GA)前に作成されたActionの移行は、一般的に以下の手順を含みます。

  1. 破壊的変更セクションで要約されているように、名前が変更され、再配置されたイベントプロパティの参照を調整します。

  2. 望み通りの副作用を説明するオブジェクトを作成および返す代わりに、「副作用の実行」セクションで要約されているように、関連するapiメソッドを呼び出して、カスタムコードを更新します。

  3. リダイレクトコールバックに対処する必要があるActionsについては、最近公開された専用機能を使用します。event.protocol === 'redirect-callback’に依存するコードを使用していた場合は、「アクションを使ったリダイレクト」を参照してください。

破壊的変更(Breaking Change)

クエリおよび本文パラメーター

event.request.queryおよびevent.request.bodyオブジェクトを使用して、クエリおよびボディーパラメーターへの直接アクセスが利用できます。これらは、GETまたはPOST要求を介して認可が開始されたかどうかに関わらず、公開されます。また認可要求の一環として送信された多くのプロトコル固有のクエリまたはボディーパラメーターは、event.transactionオブジェクトのファーストクラス値として利用できます。ユースケースがサポートされていない場合を除き、event.request.queryおよびevent.request.bodyではなくevent.transactionを使用することをお勧めします。これらの変更の完全なマッピングは以下のとおりです。

GA前のプロパティ GAのプロパティ
event.actor.ip event.request.ip
event.actor.hostname event.request.hostname
event.actor.geoIp event.request.geoip
event.actor.language event.request.language
event.actor.method event.request.method
event.actor.userAgent event.request.user_agent
event.actor.body event.request.body
event.actor.query event.request.query
event.actor.query.audience event.resource_server.identifier
event.actor.query.scope event.transaction.requested_scopes
event.actor.query.acr_values event.transaction.acr_values
event.actor.query.ui_locales event.transaction.ui_locales
event.protocol event.transaction.protocol
context.secrets event.secrets

ユーザープロファイルプロパティ

一般的に、Auth0ユーザープロファイル構造と一致させるために、event.userオブジェクトは、そのプロパティをキャメルケースからスネークケースに変更しています。たとえば、event.user.appMetadataは、event.user.app_metadataに変更されています。

副作用の実行

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

ユーザーのuser_metadataの更新

GA前のトリガー:

async function myFunction(event, context) {
  return {
    user: {
      userMetadata: {
        myParam: "foo"
      }
    }
  };
}

Was this helpful?

/

GAトリガー:

async function onExecutePostLogin(event, api) {
  api.user.setUserMetadata('myParam', 'foo');
}

Was this helpful?

/

ユーザーのapp_metadataの更新

GA前のトリガー:

async function myFunction(event, context) {
  return {
    user: {
      appMetadata: {
        myParam: "foo"
      }
    }
  };
}

Was this helpful?

/

GAトリガー:

async function onExecutePostLogin(event, api) {
  api.user.setAppMetadata('myParam', 'foo');
}

Was this helpful?

/

ログインの拒否

GA前のトリガー:

async function myFunction(event, context) {
  throw new Error("Access denied.");
}

Was this helpful?

/

GAトリガー:

async function onExecutePostLogin(event, api) {
  api.access.deny("Access denied.");
}

Was this helpful?

/

カスタムクレームをアクセストークンに追加する

GA前のトリガー:

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

Was this helpful?

/

GAトリガー:

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

Was this helpful?

/

カスタムクレームをIDトークンに追加する

GA前のトリガー:

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

Was this helpful?

/

GAトリガー:

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

Was this helpful?

/

多要素認証を動的に有効にする

GA前のトリガー:

async function myFunction(event, context) {
  return {
    command: {
      type: "multifactor",
      provider: "any"
    }
  };
}

Was this helpful?

/

GAトリガー:

async function onExecutePostLogin(event, api) {
  api.multifactor.enable("duo");
}

Was this helpful?

/

ユーザーをリダイレクトする

GA前のトリガー:

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

Was this helpful?

/

GAトリガー:

async function onExecutePostLogin(event, api) {
  api.redirect.sendUserTo("https://my-app.example.com");
}

Was this helpful?

/

パラメーターを安全に送信し、リプレイ攻撃を避けるために、リダイレクトを介したデータの受け渡しは、Actions GAでは大幅に変更されています。詳細については、「アクションを使ったリダイレクト」をお読みください。

スコープを操作する

Actions BetaでIDおよびアクセストークンスコープの直接操作の提供を試みていますが、Actions GAではこの機能をサポートしていません。