/*** @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.redirect.sendUserTo("https://my-app.exampleco.com");};
/*** @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.redirect.sendUserTo("https://my-app.exampleco.com");};/*** @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) => {}
/*** @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 YOUR_AUTH0_DOMAIN = event.secrets.YOUR_AUTH0_DOMAIN || event.request.hostname // Craft a signed session token const token = api.redirect.encodeToken({ secret: event.secrets.MY_REDIRECT_SECRET, expiresInSeconds: 60, payload: { // Custom claims to be added to the token email: event.user.email, externalUserId: 1234, continue_uri: `https://${YOUR_AUTH0_DOMAIN}/continue` }, }); // Send the user to https://my-app.exampleco.com along // with a `session_token` query string param including // the email. api.redirect.sendUserTo("https://my-app.exampleco.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) => { const payload = api.redirect.validateToken({ secret: event.secrets.PRECONFIGURED_SECRET, tokenParameterName: 'my_token', }); // use the data encoded in the token, such as: api.idToken.setCustomClaim('color', payload.favorite_color);}
const CUSTOM_METHOD_URL = "https://path.to.prompt";const PROMPT_TTL = 1000 * 60 * 60 * 24; // 24h/** * 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) => { // Search authentication method records for an entry representing our // custom method. const methodRecord = event.authentication?.methods.find((record) => validateCustomRecord(record, CUSTOM_METHOD_URL, PROMPT_TTL) ); if (!methodRecord) { const sessionToken = api.redirect.encodeToken({ payload: { user_id: event.user.user_id, }, secret: event.secrets.SESSION_TOKEN_SECRET, }); // We didn't find a valid record, so we send the user to the // URL that implements the custom method with the signed // data we encoded in `sessionToken`. api.redirect.sendUserTo(CUSTOM_METHOD_URL, { query: { session_token: sessionToken }, }); }};/** * Handler that will be invoked when this action is resuming after an * external redirect. If your onExecutePostLogin function does not perform * a redirect, this function can be safely ignored. * * @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) => { const payload = api.redirect.validateToken({ secret: event.secrets.SESSION_TOKEN_SECRET, tokenParameterName: "session_token", }); if (!validateSessionToken(payload)) { return api.access.deny("Unauthorized"); } // Record the completion of our custom authentication method. // THIS NEW API IS ONLY AVAILABLE IN `onContinuePostLogin`. api.authentication.recordMethod(CUSTOM_METHOD_URL);};function validateCustomRecord(record, url, ttl) { if (!record) { // No record means it isn't valid. return false; } if (record.url !== url) { // This isn't a record of our custom method. return false; } // Timestamps are rendered as ISO8601 strings. const timestamp = new Date(record.timestamp); // The record is valid if it was recorded recently enough. return timestamp.valueOf() >= Date.now() - ttl;}function validateSessionToken(payload) { // Custom validation logic for the data returned by the // custom method goes here. return true;}