Hi Everyone,
We are using react sign-in widget for our authentication and would like to enable the okta verify push notification flow for it. Below is our code for sample, can someone please help how to enable the okta verify push notification flow for it ?
It’s a SPA (single page application)
const Login = ({ setCorsErrorModalOpen }: LoginProps) => {
const { oktaAuth } = useOktaAuth();
const widgetRef: any = useRef();
// Fetch otp and state from query params from email callback verification URI
// Application should have http://localhost:8080/login as the email callback verification URI
const queryParams = new URLSearchParams(window.location.search);
const state = queryParams?.get('state') ?? '';
useEffect(() => {
if (!widgetRef.current) {
return;
}
const { issuer, clientId, redirectUri, scopes, useInteractionCode } = config.oidc;
const widget = new OktaSignIn({
/**
* Note: when using the Sign-In Widget for an OIDC flow, it still
* needs to be configured with the base URL for your Okta Org. Here
* we derive it from the given issuer for convenience.
*/
baseUrl: issuer.split('/oauth2')[0],
clientId,
redirectUri,
logo,
i18n: {
en: {
'primaryauth.title': 'Hi, Welcome back 👋',
},
},
authParams: {
// To avoid redirect do not set "pkce" or "display" here. OKTA-335945
issuer,
scopes,
},
useInteractionCodeFlow: useInteractionCode, // Set to true, if your org is OIE enabled
state,
});
widget.renderEl(
{ el: widgetRef.current },
(res: any) => {
oktaAuth.handleLoginRedirect(res.tokens);
},
(err) => {
throw err;
},
);
// Note: Can't distinguish CORS error from other network errors
const isCorsError = (err: any) => (err.name === 'AuthApiError' && !err.statusCode);
widget.on('afterError', ({_context, error}: any) => {
if (isCorsError(error)) {
setCorsErrorModalOpen(true);
}
});
return () => widget.remove();
}, [oktaAuth]);