/** * @param {Event} event - Details about the user and the context in which they are logging in. * @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login. */exports.onExecutePostLogin = async (event, api) => { if (event.user.email && event.user.email.endsWith("@example.com") && event.client.name === "My SPA") { api.access.deny(`Access to ${event.client.name} is not allowed.`); }};
/** * @param {Event} event - Details about the user and the context in which they are logging in. * @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login. */ 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."); } }}
/** * @param {Event} event - Details about the user and the context in which they are logging in. * @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login. */ exports.onExecutePostLogin = async (event, api) => { // In Actions, an API will be referred to as a Resource Server. if (event.resource_server && event.resource_server.identifier === "http://todoapi2.api") { api.access.deny("end_users_not_allowed"); }}
/** * @param {Event} event - Details about the user and the context in which they are logging in. * @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login. */exports.onExecutePostLogin = async (event, api) => { const namespace = 'https://my-app.example.com'; if (event.authorization) { api.idToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles); api.accessToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles); }}
/** * @param {Event} event - Details about the user and the context in which they are logging in. * @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login. */exports.onExecutePostLogin = async (event, api) => { api.user.setUserMetadata("favorite_color", "blue");};
/** * @param {Event} event - Details about the user and the context in which they are logging in. * @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login. */exports.onExecutePostLogin = async (event, api) => { // Require MFA for anyone logging in from North America. if (event.request.geoip.continentCode === "NA") { api.multifactor.enable("any"); };};
/*** Handler that will be called during the execution of a PostLogin flow.** @param {Event} event - Details about the user and the context in which they are logging in.* @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.*/exports.onExecutePostLogin = async (event, api) => { // Check if a passkey was used to authenticate const skipMFA = event.authentication?.methods.some( (method) => method.name === "passkey" ); // If a passkey was used skip MFA if (skipMFA) { api.multifactor.enable("none"); }};
/** * @param {Event} event - Details about the user and the context in which they are logging in. * @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login. */exports.onExecutePostLogin = async (event, api) => { // Skip the redirect if the user has already chosen a favorite color. if (event.user.user_metadata.favorite_color) { return; } const token = api.redirect.encodeToken({ secret: event.secrets.MY_SHARED_SECRET, payload: { email: event.user.email, }, }); // Send the user to https://my-app.example.com along // with a `session_token` query string param. api.redirect.sendUserTo("https://my-app.example.com", { query: { session_token: token } });};/** * @param {Event} event - Details about the user and the context in which they are logging in. * @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login. */exports.onContinuePostLogin = async (event, api) => { // Once the /continue endpoint has been called, unpack the signed token // and store the favorite color as user metadata. const payload = api.redirect.validateToken({ secret: event.secrets.MY_SHARED_SECRET, }); api.user.setUserMetadata("favorite_color", payload.favorite_color);};
/** * @param {Event} event - Details about the user and the context in which they are logging in. * @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login. */exports.onExecutePostLogin = async (event, api) => { if (event?.resource_server?.identifier === 'https://example.com/api') { api.accessToken.addScope("read:xyz"); }};