# Missing authentication code on idpDiscovery login

**URL:** <https://devforum.okta.com/t/missing-authentication-code-on-idpdiscovery-login/11108>\
**Category:** Questions\
**Created:** [September 28, 2020, 5:00pm UTC](https://devforum.okta.com/t/missing-authentication-code-on-idpdiscovery-login/11108 "2020-09-28T17:00:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mathieuv](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@mathieuv](https://devforum.okta.com/u/mathieuv)\
**Post date:** [September 28, 2020, 5:00pm UTC](https://devforum.okta.com/t/missing-authentication-code-on-idpdiscovery-login/11108/1 "2020-09-28T17:00:02Z")

</div>

Hello,

I am currently experimenting with the Okta widget to integrate in a React SPA. I am using the [samples-js-react/custom-login at master · okta/samples-js-react · GitHub](https://github.com/okta/samples-js-react/tree/master/custom-login) project for my tests. It works with email+password. However when connecting via an external Identity Provider, Okta doesn’t return an authentication code.  
I am properly redirected to the Identity Provider, the authentication is validated (The events show success in the System Log), but the redirection to the route `/implicit/callback` does not contain the authentication code. Instead, Okta redirects to `http://localhost:3000/implicit/callback?fromLogin=true`, so the authentication process doesn’t complete.

The `OktaSignIn` configuration:

```javascript
{
      baseUrl,
      clientId,
      redirectUri: 'http://localhost:3000/implicit/callback',
      features: {
        idpDiscovery: true
      },
      idpDiscovery: {
        requestContext: 'http://localhost:3000/implicit/callback'
      },
      authParams: {
        pkce: true,
        issuer,
        display: 'page',
        responseMode: 'query',
        scopes: ['openid'],
      },

```

This topic seems to have the same symptoms [Okta sign-in widget does not complete sign-in after authentication with IDP](https://devforum.okta.com/t/okta-sign-in-widget-does-not-complete-sign-in-after-authentication-with-idp/6913) Was any solution found for this issue?

Thanks,

mathieuv

---

<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:** [September 28, 2020, 11:04pm UTC](https://devforum.okta.com/t/missing-authentication-code-on-idpdiscovery-login/11108/2 "2020-09-28T23:04:17Z")

</div>

When users log in through an external IDP, the authorize call will not be made and by default they will wind up on their Okta dashboard if you do not set a requestContext. Setting the requestContext to the callback route means login will not occur because, like I said, the authorize call was never made in the first place and the callback route has no authorization code with which to exchange for tokens. So, instead of setting the requestContext to the callback route, you will want to instead redirect to a route that is able to make the authorize call for the user once they are authenticated with Okta.

One way to handle this is to redirect the user to your main or login page, with logic on that page that will make a silent authorize call (AuthJS’ [getWithoutPrompt](https://github.com/okta/okta-auth-js#tokengetwithoutpromptoptions) can do this for you without redirecting the user again) if the user has an existing Okta session (instead of loading the widget).

---

<div class="post-metadata">

**Author:** ![mathieuv](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@mathieuv](https://devforum.okta.com/u/mathieuv)\
**Post date:** [September 30, 2020, 4:13pm UTC](https://devforum.okta.com/t/missing-authentication-code-on-idpdiscovery-login/11108/3 "2020-09-30T16:13:35Z")

</div>

Thank you for the reply, it was exactly what I needed (although I used `getWithRedirect` to not rely on 3rd party cookies.

---

<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:** [October 16, 2020, 2:49pm UTC](https://devforum.okta.com/t/missing-authentication-code-on-idpdiscovery-login/11108/4 "2020-10-16T14:49:51Z")

</div>

Closed on October 16, 2020, 2:49pm UTC

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