たとえば、平日のみにアクセスを許可したいアプリケーションがあるとします。新しいアクションを作成し、ログインフローにアクションを追加するためにLogin / Post Loginトリガーを選択します。以下のコードを[Actions Code Editor(アクションコードエディター)]にコピーします。
exports.onExecutePostLogin = async (event, api) => { if (event.client.name === "APP_NAME") { const d = new Date().getDay(); if (d === 0 || d === 6) { api.access.deny("This app is only available during the week."); } }}
たとえば、アプリケーションへのアクセスを許可するのに、企業ネットワークの内側からアクセスするユーザーに限定したいとします。新しいアクションを作成し、ログインフローにアクションを追加するためにLogin / Post loginトリガーを選択します。以下のコードをActionsコードエディターにコピーします。
const ipaddr = require("ipaddr.js");exports.onExecutePostLogin = async (event, api) => { const corpNetwork = "192.168.1.134/26"; const currentIp = ipaddr.parse(event.request.ip); if (!currentIp.match(ipaddr.parseCIDR(corpNetwork))) { api.access.deny("This app is only available from inside the corporate network."); };};
exports.onExecutePostLogin = async (event, api) => { // In Actions, an API will be referred to as a Resource Server. const { identifier } = event.resource_server || {}; if (identifier === "https://api.example.com") { api.access.deny("end_users_not_allowed"); }}
Auth0が発行したトークンにユーザーロールを追加するには、event.authorizationオブジェクトとapi.idToken.setCustomClaimおよびapi.accessToken.setCustomClaimメソッドを使用します。新しいアクションを作成し、ログインフローにアクションを追加するためにLogin / Post loginトリガーを選択します。以下のコードをActionsコードエディターにコピーします。