# Javascript Okta Sign-In Widget - MFA not properly working

**URL:** <https://devforum.okta.com/t/javascript-okta-sign-in-widget-mfa-not-properly-working/17813>\
**Category:** Questions\
**Created:** [November 2, 2021, 5:36pm UTC](https://devforum.okta.com/t/javascript-okta-sign-in-widget-mfa-not-properly-working/17813 "2021-11-02T17:36:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![TimFranklin](https://avatars.discourse-cdn.com/v4/letter/t/898d66/32.png) [@TimFranklin](https://devforum.okta.com/u/TimFranklin)\
**Post date:** [November 2, 2021, 5:36pm UTC](https://devforum.okta.com/t/javascript-okta-sign-in-widget-mfa-not-properly-working/17813/1 "2021-11-02T17:36:30Z")

</div>

Hi all, I’m having issues with the javascript/web based Okta sign-in widget on ipads when MFA is enabled. My app requires that the user re-authenticate with MFA per session, so I have that rule enabled in my app.

 ![image](https://global.discourse-cdn.com/oktadev/original/2X/1/1b9fc3c545e0193fe17010031940ec481bbe64d9.png)

I added the prompt parameter in the OktaSignIn constructor and it seems to work within the browser on windows, OSX, and Android devices. But somehow when used on an iOS device in any browser, I get an error

**Error found on my Ipad:**

> “the current sign on policy requires this client to redirect for re-authentication for MFA. Please contact your administrator.”

**Code Snippet:**

```auto
        const oktaSignIn = new OktaSignIn({
          baseUrl: `https://${OKTA_ORG_URL}`,
          redirectUri: REDIRECT_URI,
          clientId: OKTA_CLIENT_ID,
          authParams: {
            issuer: `https://${OKTA_ORG_URL}/oauth2/default`
          },
          prompt: "login" // * this seems to make MFA work
        });

        function loggedInHandler(user){
            //......logged in logic
        }

        function authFailureHandler(error){

          oktaSignIn.showSignInToGetTokens({
            el: '#okta-login-container'
          }).then(function(tokens) {
            oktaSignIn.authClient.tokenManager.setTokens(tokens);
            oktaSignIn.remove();
            const idToken = tokens.idToken;
            window.location.replace(HOME_URI) 
          }).catch(function(err) {
            console.error(err);
          });
        }
        
        oktaSignIn.authClient.token.getUserInfo().then(loggedInHandler, authFailureHandler);
  

```

![image](https://global.discourse-cdn.com/oktadev/original/2X/9/95654b30860890fafcec539de3aea9b641cdc775.png)

**Questions:**

1. How do your properly configure MFA within the sign-in widget.
2. Is MFA in the widget supported on Ipads in firefox/chrome
3. Has anyone seen good samples for this

Any help on this would be greatly appreciated. Thank you!

---

<div class="post-metadata">

**Author:** ![andrea](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/andrea/32/2172_2.png) [@andrea](https://devforum.okta.com/u/andrea)\
**Post date:** [November 2, 2021, 6:09pm UTC](https://devforum.okta.com/t/javascript-okta-sign-in-widget-mfa-not-properly-working/17813/2 "2021-11-02T18:09:30Z")

</div>

Try using showSignInAndRedirect instead of showSignInToGetTokens.

A self-hosted widget cannot prompt a user for app-level MFA, they must be redirected to Okta (via the /authorize URL) to get prompted accordingly.

---

<div class="post-metadata">

**Author:** ![TimFranklin](https://avatars.discourse-cdn.com/v4/letter/t/898d66/32.png) [@TimFranklin](https://devforum.okta.com/u/TimFranklin)\
**Post date:** [November 2, 2021, 6:56pm UTC](https://devforum.okta.com/t/javascript-okta-sign-in-widget-mfa-not-properly-working/17813/3 "2021-11-02T18:56:08Z")

</div>

Hi Andrea, Thank you for your help. I updated my code ro use showSignInAndRedirect and am getting an error in the query parameter:  
PKCE code challenge is required when the token endpoint authentication method is ‘NONE’.  
Using this approach, how do you work around this issue?

I should add that the application is entirely a front-end based application.

---

<div class="post-metadata">

**Author:** ![andrea](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/andrea/32/2172_2.png) [@andrea](https://devforum.okta.com/u/andrea)\
**Post date:** [November 2, 2021, 8:29pm UTC](https://devforum.okta.com/t/javascript-okta-sign-in-widget-mfa-not-properly-working/17813/4 "2021-11-02T20:29:46Z")

</div>

huh, it should be defaulting to use PKCE, but can you try setting `pkce: true` in your [widget config](https://github.com/okta/okta-signin-widget#openid-connect)?

The app you created in Okta is a SPA, right?

---

<div class="post-metadata">

**Author:** ![TimFranklin](https://avatars.discourse-cdn.com/v4/letter/t/898d66/32.png) [@TimFranklin](https://devforum.okta.com/u/TimFranklin)\
**Post date:** [November 2, 2021, 9:12pm UTC](https://devforum.okta.com/t/javascript-okta-sign-in-widget-mfa-not-properly-working/17813/5 "2021-11-02T21:12:34Z")

</div>

Setting the pkce to true did work. I received both code and a state parameters back successfully.

It is an SPA. I’m now trying to track down an approach for handling these values on the front end. I can only use vanilla javascript for this project.

Thank you!

---

<div class="post-metadata">

**Author:** ![andrea](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/andrea/32/2172_2.png) [@andrea](https://devforum.okta.com/u/andrea)\
**Post date:** [November 2, 2021, 9:26pm UTC](https://devforum.okta.com/t/javascript-okta-sign-in-widget-mfa-not-properly-working/17813/6 "2021-11-02T21:26:24Z")

</div>

Take a look at [handleLoginRedirect](https://github.com/okta/okta-auth-js#handleloginredirecttokens-originaluri) which can handle the callback. Check out the example from our SDK docs below for [isLoginRedirect](https://github.com/okta/okta-auth-js#isloginredirect) for how to check if a callback is happening

```auto
if (authClient.isLoginRedirect()) {
  // callback flow
  try {
    await authClient.handleLoginRedirect();
  } catch (e) {
    // log or display error details
  }
} else {
  // normal app flow
}

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/oktadev/original/1X/589c4c5f80de422d01f47cee7185a7fb8227835c.png) [@system](https://devforum.okta.com/u/system)\
**Post date:** [February 8, 2024, 7:52pm UTC](https://devforum.okta.com/t/javascript-okta-sign-in-widget-mfa-not-properly-working/17813/7 "2024-02-08T19:52:08Z")

</div>

Closed on February 8, 2024, 7:52pm UTC

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
