My use-case is that I want to forward the Okta user ID to user analytics once the user has signed in, and manage this from the Okta side, to avoid needing to implement the same functionality across all SSO apps. The user signs into to an OIE, okta-hosted widget.
I’ve tried using the hooks functionality mentioned here: okta/okta-signin-widget: HTML/CSS/JS widget that provides out-of-the-box authentication UX for your organization’s apps (github.com)
Currently I have a post-event hook configured to run after the success-redirect
event. The hook attempts to call the Sessions API to learn some details about the signed in user. However, this event appears to run before the okta widget exchanges its stateToken for a session cookie, and so the call fails.
Is there a later event I can place a hook on, or can I place some Javascript in the interstitial page itself to collect some user analytics?
var config = OktaUtil.getSignInWidgetConfig();
config.hooks = {
'success-redirect': {
after: [
async function afterSuccessRedirect() {
return new Promise((resolve, reject) => {
console.log("HOOK: AFTER SUCCESS REDIRECT");
let xhr = new XMLHttpRequest();
xhr.open("GET", "https://<okta_custom_domain>.com/api/v1/sessions/me");
xhr.onload = (event) => {
console.log("HOOK ASR Done");
console.log(xhr.responseText);
resolve();
}
xhr.onerror = (event) => {
console.log("HOOK ASR XHR Error ", event);
resolve();
}
xhr.send();
});
}
]
}
}