# JS Sign-In Widget Quickstart hasTokensInUrl undefined

**URL:** <https://devforum.okta.com/t/js-sign-in-widget-quickstart-hastokensinurl-undefined/6767>\
**Category:** Questions\
**Created:** [October 31, 2019, 3:53pm UTC](https://devforum.okta.com/t/js-sign-in-widget-quickstart-hastokensinurl-undefined/6767 "2019-10-31T15:53:25Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![stuart.sierra.drest](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@stuart.sierra.drest](https://devforum.okta.com/u/stuart.sierra.drest)\
**Post date:** [October 31, 2019, 3:53pm UTC](https://devforum.okta.com/t/js-sign-in-widget-quickstart-hastokensinurl-undefined/6767/1 "2019-10-31T15:53:25Z")

</div>

Hello,

I am testing a new single-page app with an Okta dev account.

I am following the instructions for the JavaScript widget at [Okta Sign-In Widget Quickstart](https://developer.okta.com/quickstart/#okta-sign-in-widget-quickstart).

Per the instructions, I added the CDN links for version 3.2.0 of the Sign-In Widget to my HTML page. Next I added a `<div id="okta-login-container"></div>` and the example `<script>` block, replacing the placeholders `yourOktaDomain` and `clientId` with the appropriate values.

On load, the JavaScript console logs an error:

```auto
(index):21 Uncaught TypeError: Cannot read property 'hasTokensInUrl' of undefined

```

In the JS console, I can see that the `oktaSignIn` object does not have a property named `session`, as the sample code seems to expect.

Thank you.

---

<div class="post-metadata">

**Author:** ![dragos](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/dragos/32/1313_2.png) [@dragos](https://devforum.okta.com/u/dragos)\
**Post date:** [November 1, 2019, 6:49am UTC](https://devforum.okta.com/t/js-sign-in-widget-quickstart-hastokensinurl-undefined/6767/2 "2019-11-01T06:49:39Z")

</div>

Hi @stuart.sierra.drest

Can you please provide the full script that you are using in order to see what is the cause of the issue?

---

<div class="post-metadata">

**Author:** ![stuart.sierra.drest](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@stuart.sierra.drest](https://devforum.okta.com/u/stuart.sierra.drest)\
**Post date:** [November 4, 2019, 3:36pm UTC](https://devforum.okta.com/t/js-sign-in-widget-quickstart-hastokensinurl-undefined/6767/3 "2019-11-04T15:36:38Z")

</div>

Hello,

I should clarify that I’m not seeking assistance. I only wanted to report that the sample code on this page does not work:  
[https://developer.okta.com/quickstart/#/widget/nodejs/express](https://developer.okta.com/quickstart/#/widget/nodejs/express)

The code I’m referring to is under the heading **“Configure the Sign-In Widget”** and begins with the following lines:

```auto
<script type="text/javascript">
  var oktaSignIn = new OktaSignIn({
    baseUrl: "https://${yourOktaDomain}",
    clientId: "{clientId}",
    authParams: {
      issuer: "https://${yourOktaDomain}/oauth2/default",
      responseType: ['token', 'id_token'],
      display: 'page'
    }
  });
  if (oktaSignIn.token.hasTokensInUrl()) {
    oktaSignIn.token.parseTokensFromUrl(

```

When I tried to use this sample code it failed with the error I reported. Perhaps this is due to a change in the public API of `OktaSignIn` since that example was written.

Hope this helps.  
–S

---

<div class="post-metadata">

**Author:** ![bryceroney](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/bryceroney/32/1425_2.png) [@bryceroney](https://devforum.okta.com/u/bryceroney)\
**Post date:** [November 4, 2019, 11:41pm UTC](https://devforum.okta.com/t/js-sign-in-widget-quickstart-hastokensinurl-undefined/6767/4 "2019-11-04T23:41:22Z")

</div>

Yes, I’m having the same issue.

It seems `hasTokensInUrl` works on the root `oktaSignIn` object but then fails again at the session property.

---

<div class="post-metadata">

**Author:** ![rburrows](https://avatars.discourse-cdn.com/v4/letter/r/71e660/32.png) [@rburrows](https://devforum.okta.com/u/rburrows)\
**Post date:** [November 7, 2019, 6:13am UTC](https://devforum.okta.com/t/js-sign-in-widget-quickstart-hastokensinurl-undefined/6767/5 "2019-11-07T06:13:55Z")

</div>

For anyone looking for the 3.0+ compatible API changes pending the guide update:

* * *

`oktaSignIn.token.hasTokensInUrl`  
–\>  
`oktaSignIn.hasTokensInUrl`

* * *

`oktaSignIn.token.parseTokensFromUrl`  
–\>  
`oktaSignIn.authClient.token.parseFromUrl`

* * *

`oktaSignIn.session.get(function (res) {...`  
–\>  
`oktaSignIn.authClient.session.get().then(function (res) {...`

---

<div class="post-metadata">

**Author:** ![unnir](https://avatars.discourse-cdn.com/v4/letter/u/aca169/32.png) [@unnir](https://devforum.okta.com/u/unnir)\
**Post date:** [December 17, 2019, 5:52pm UTC](https://devforum.okta.com/t/js-sign-in-widget-quickstart-hastokensinurl-undefined/6767/6 "2019-12-17T17:52:16Z")

</div>

Thanks for the assist, that was my issue as well and is now fixed. It would be good to have this documentation page updated to the suggestion above to responding to the API change:

[https://developer.okta.com/quickstart/#/widget/dotnet/aspnetcore](https://developer.okta.com/quickstart/#/widget/dotnet/aspnetcore)

---

<div class="post-metadata">

**Author:** ![mraible](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/mraible/32/37_2.png) [@mraible](https://devforum.okta.com/u/mraible)\
**Post date:** [January 16, 2020, 3:48pm UTC](https://devforum.okta.com/t/js-sign-in-widget-quickstart-hastokensinurl-undefined/6767/7 "2020-01-16T15:48:43Z")

</div>

Thanks for detailing the fixes @rburrows. I created a PR to fix this. [https://github.com/okta/okta-developer-docs/pull/883](https://github.com/okta/okta-developer-docs/pull/883)

---

<div class="post-metadata">

**Author:** ![talents](https://avatars.discourse-cdn.com/v4/letter/t/9de0a6/32.png) [@talents](https://devforum.okta.com/u/talents)\
**Post date:** [January 19, 2020, 10:16am UTC](https://devforum.okta.com/t/js-sign-in-widget-quickstart-hastokensinurl-undefined/6767/8 "2020-01-19T10:16:45Z")

</div>

@mraible this still doesn’t work for me. Before this fix the login didn’t show at all - with this fix I get a 400 error response when logging in  
Error Code: invalid\_request  
Description: The ‘redirect\_uri’ parameter must be an absolute URI that is whitelisted in the client app settings.

The redirect URI is, as specified in the guide, `window.location.origin + "/implicit/callback"`. This logs localhost:3000 as it should

---

<div class="post-metadata">

**Author:** ![mraible](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/mraible/32/37_2.png) [@mraible](https://devforum.okta.com/u/mraible)\
**Post date:** [January 19, 2020, 4:19pm UTC](https://devforum.okta.com/t/js-sign-in-widget-quickstart-hastokensinurl-undefined/6767/9 "2020-01-19T16:19:16Z")

</div>

Your redirect URIs need to be added to your app on Okta. Add `http://localhost:3000/implicit/callback` to your app and it should work.

---

<div class="post-metadata">

**Author:** ![talents](https://avatars.discourse-cdn.com/v4/letter/t/9de0a6/32.png) [@talents](https://devforum.okta.com/u/talents)\
**Post date:** [January 22, 2020, 6:17pm UTC](https://devforum.okta.com/t/js-sign-in-widget-quickstart-hastokensinurl-undefined/6767/10 "2020-01-22T18:17:04Z")

</div>

This is not the solution

---

<div class="post-metadata">

**Author:** ![mraible](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/mraible/32/37_2.png) [@mraible](https://devforum.okta.com/u/mraible)\
**Post date:** [January 22, 2020, 6:46pm UTC](https://devforum.okta.com/t/js-sign-in-widget-quickstart-hastokensinurl-undefined/6767/11 "2020-01-22T18:46:33Z")

</div>

When you see the 400 error in your browser, go to your address bar and look for the `redirect_uri` parameter that your app is sending. You might want to copy/paste the URL into a text editor so it’s easier to find. If you add this value to the Login redirect URIs in your Okta app, you should see the login form on Okta. At least, that’s how I solved it in the past.

---

<div class="post-metadata">

**Author:** ![Justin](https://avatars.discourse-cdn.com/v4/letter/j/3ab097/32.png) [@Justin](https://devforum.okta.com/u/Justin)\
**Post date:** [February 4, 2020, 6:35pm UTC](https://devforum.okta.com/t/js-sign-in-widget-quickstart-hastokensinurl-undefined/6767/12 "2020-02-04T18:35:15Z")

</div>

I’m following the guide mentioned above: [https://developer.okta.com/quickstart/#/widget/nodejs/express](https://developer.okta.com/quickstart/#/widget/nodejs/express)

I added this to the code here: [https://developer.okta.com/code/nodejs/](https://developer.okta.com/code/nodejs/)

I have my Login redirect URIs set to:  
[http://localhost:8080/authorization-code/callback](http://localhost:8080/authorization-code/callback)  
[http://localhost:8080/implicit/callback](http://localhost:8080/implicit/callback)

However, when I attempt to sign in with the widget, I receive a 400 error response similar to @talents. When I look at the address bar, my redirect\_uri seems to be [http://localhost:8080](http://localhost:8080)

When, I update the url so that the redirect\_uri looks like this: redirect\_uri=http%3A%2F%2Flocalhost%3A8080%2Fauthorization-code%2Fcallback  
I am redirected to the appropriate screen in my app.

Anymore thoughts on this issue?

---

<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:** [February 7, 2020, 12:34am UTC](https://devforum.okta.com/t/js-sign-in-widget-quickstart-hastokensinurl-undefined/6767/13 "2020-02-07T00:34:53Z")

</div>

Justin, can you also add [http://localhost:8080](http://localhost:8080) as a login redirect uri for your app in Okta? The Redirect URI in the /authorize call (so the one you see in your address bar) MUST be an exact match (case sensitive) with one of the ones listed in Okta.

---

<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:** [April 25, 2022, 5:54pm UTC](https://devforum.okta.com/t/js-sign-in-widget-quickstart-hastokensinurl-undefined/6767/14 "2022-04-25T17:54:54Z")

</div>

Closed on April 25, 2022, 5:54pm UTC

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