# Get a new token issue

**URL:** <https://community.auth0.com/t/get-a-new-token-issue/111690>\
**Category:** Get Help\
**Tags:** configuration, application\
**Created:** [July 20, 2023, 2:18pm UTC](https://community.auth0.com/t/get-a-new-token-issue/111690 "2023-07-20T14:18:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![luis.ponce1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/luis.ponce1/32/49082_2.png) [@luis.ponce1](https://community.auth0.com/u/luis.ponce1)\
**Post date:** [July 20, 2023, 2:18pm UTC](https://community.auth0.com/t/get-a-new-token-issue/111690/1 "2023-07-20T14:18:39Z")

</div>

Hello I have a problem. I’m trying to get a new token after the token I already had expired in my SPA. The problem is the endpoint returns the following error:

```auto
{
    "error": "access_denied",
    "error_description": "Cannot read property 'audience' of undefined"
}

```

I already have the refresh token rotation activated and I checked that my custom rules were not causing conflicts.

EDIT. This is my payload when I execute getTokenSilently:

````auto
  "client_id": "###",
  "grant_type": "refresh_token",
  "refresh_token": "####",
  "redirect_uri": "http://127.0.0.1:3000/authorize"
}```
````

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [July 20, 2023, 10:19pm UTC](https://community.auth0.com/t/get-a-new-token-issue/111690/5 "2023-07-20T22:19:10Z")

</div>

Hey there @luis.ponce1 welcome to the community!

> [@luis.ponce1](#):
>
> I’m trying to get a new token after the token I already had expired in my SPA.

Which SPA SDK are you using in particular? What happens if you don’t pass any params and just call `getTokenSilently`? Are you using [authorizationParams](https://auth0.github.io/auth0-spa-js/interfaces/GetTokenSilentlyOptions.html#authorizationParams)?

Keep us posted!

---

<div class="post-metadata">

**Author:** ![luis.ponce1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/luis.ponce1/32/49082_2.png) [@luis.ponce1](https://community.auth0.com/u/luis.ponce1)\
**Post date:** [July 21, 2023, 1:54pm UTC](https://community.auth0.com/t/get-a-new-token-issue/111690/6 "2023-07-21T13:54:29Z")

</div>

Hello, thanks for the welcome and for answering.

I am using `@auth0/auth0-spa-js`. The issue that I describe in the post is the same when using getTokenSilently I pass `authorizationParams` to it or not. It’s also worth mentioning that I try to run `getTokenSilently` before and after the token expires, and the result is the same.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [July 21, 2023, 9:14pm UTC](https://community.auth0.com/t/get-a-new-token-issue/111690/7 "2023-07-21T21:14:25Z")

</div>

Thanks for confirming @luis.ponce1 ! Are you able to decode the initial access token at [jwt.io](http://jwt.io)?

I have seen similar issues arise when there is a misconfiguration causing 2 separate `/authorize` requests to run at the same time - Similar to what is described here:

> <https://github.com/auth0/auth0-spa-js/issues/109#issuecomment-515605361>
>
> Hi!
> 
> I'm having an error in the console when creating the Auth0 client using \`…createAuth0Client()\`.
> 
> The error is the following:
> 
> \`\`\`
> \> ERROR TypeError: Cannot read property 'close' of undefined
> at o (auth0-spa-js.production.js:formatted:1)
> at ZoneDelegate.invokeTask (zone-evergreen.js:391)
> at Object.onInvokeTask (auth0-spa-js.production.js:formatted:1)
> at ZoneDelegate.invokeTask (zone-evergreen.js:390)
> at Zone.runTask (zone-evergreen.js:168)
> at ZoneTask.invokeTask \[as invoke\] (zone-evergreen.js:465)
> at invokeTask (zone-evergreen.js:1603)
> at globalZoneAwareCallback (zone-evergreen.js:1640)
> \`\`\`
> On the beautyfied production code, the error points to this line:
> \`\`\`js
> o = function(i) {
> // Below is the culprit, apparently, 'i.source' is undefined
> i.origin == m && i.data && "authorization\_response" === i.data.type && (i.source.close(),
> i.data.response.error ? t(i.data.response) : e(i.data.response),
> clearTimeout(n),
> window.removeEventListener("message", o, !1),
> window.document.body.removeChild(r))
> };
> \`\`\`
> 
> And the code that's calling the \`createAuth0Client()\` function is this one (pretty much the exact same as the \[Angular Login Tutorial\](https://auth0.com/docs/quickstart/spa/angular2#add-an-authentication-service)):
> 
> \`\`\`typescript
> // This is a method of my AuthService
> async getAuth0Client(): Promise\<Auth0Client\> {
> if (!this.auth0Client) {
> console.log("AuthService - generating new Auth0Client");
> this.auth0Client = await createAuth0Client(environment.auth0);
> console.log("AuthService - new Auth0Client", this.auth0Client);
> 
> // Provide the current value of isAuthenticated
> this.isAuthenticated.next(await this.auth0Client.isAuthenticated());
> 
> // Whenever isAuthenticated changes, provide the current value of \`getUser\`
> this.isAuthenticated
> .subscribe(async isAuthenticated =\> await this.updateUserProfile(isAuthenticated));
> }
> return this.auth0Client;
> }
> \`\`\`
> 
> Note that this error does not prevent the client to be effectively created and functionning. But it's still an unwanted error 😄 
> 
> Also, some other people seem to have the same kind of issue, see \[this thread in the Auth0 Community Forums\](https://community.auth0.com/t/typeerror-cannot-read-property-close-of-undefined-when-using-new-auth0-spa-library-in-angular-interceptor/28010)

---

<div class="post-metadata">

**Author:** ![luis.ponce1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/luis.ponce1/32/49082_2.png) [@luis.ponce1](https://community.auth0.com/u/luis.ponce1)\
**Post date:** [August 1, 2023, 3:14pm UTC](https://community.auth0.com/t/get-a-new-token-issue/111690/8 "2023-08-01T15:14:07Z")

</div>

Hi @ty.frith , apologies for the absence. These last few days I had little time to follow up on this bug and focused on other features. I want to tell you that yesterday I found the solution. It turns out that the problem was in the bad configuration of some custom rules, as I read in the solution of this other post:

> [@React Native - Refresh token not working](https://community.auth0.com/t/react-native-refresh-token-not-working/7999):
>
> import Auth0 from 'react-native-auth0'; const auth0 = new Auth0(credentials); getToken = (authData) =\> { auth0 .auth .refreshToken({refreshToken: authData.refreshToken}) .then(credentials =\> {console.log(credentials); return credentials.idToken}) .catch(err =\> {console.log(err)}); } This gives error: { "error": "access\_denied", "error\_description": "Cannot read property 'audience' of undefined" }

Thank you very much for your help.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [August 1, 2023, 3:17pm UTC](https://community.auth0.com/t/get-a-new-token-issue/111690/9 "2023-08-01T15:17:08Z")

</div>

Hey @luis.ponce1 no problem, happy to help! Thanks for following up here 🙏

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [August 15, 2023, 3:17pm UTC](https://community.auth0.com/t/get-a-new-token-issue/111690/10 "2023-08-15T15:17:23Z")

</div>

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