# onContinuePostLogin: The session token is invalid: Unexpected token payload type

**URL:** <https://community.auth0.com/t/oncontinuepostlogin-the-session-token-is-invalid-unexpected-token-payload-type/88757>\
**Category:** Get Help\
**Created:** [August 15, 2022, 9:44am UTC](https://community.auth0.com/t/oncontinuepostlogin-the-session-token-is-invalid-unexpected-token-payload-type/88757 "2022-08-15T09:44:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![felix.seidl](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/felix.seidl/32/12949_2.png) [@felix.seidl](https://community.auth0.com/u/felix.seidl)\
**Post date:** [August 15, 2022, 9:44am UTC](https://community.auth0.com/t/oncontinuepostlogin-the-session-token-is-invalid-unexpected-token-payload-type/88757/1 "2022-08-15T09:44:36Z")

</div>

Hi,

I’m working on Post Login action that uses a redirect and then tries to access some data from an external website.

when calling validateToken I’m getting an error (“The session token is invalid: Unexpected token payload type”) and I don’t know exactly what the problem is.

The token I’m returning looks like this:

```auto
{
  "state": "hKF***",
  "favorite_color": "blue",
  "iat": 1660555965,
  "sub": "auth0|***",
  "iss": "***.azurewebsites.net",
  "exp": 1660556025
}

```

I’m signing the token with HS256 and a shared key both known to the action and the external service.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [August 26, 2022, 9:26pm UTC](https://community.auth0.com/t/oncontinuepostlogin-the-session-token-is-invalid-unexpected-token-payload-type/88757/2 "2022-08-26T21:26:29Z")

</div>

Hi @felix.seidl,

Welcome to the Auth0 Community!

How are you creating the token? Can you give us a code snippet of your action?

Also have you tried checking your token with [jwt.io](http://jwt.io) to see if it is valid?

Let me know,  
Dan

---

<div class="post-metadata">

**Author:** ![felix.seidl](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/felix.seidl/32/12949_2.png) [@felix.seidl](https://community.auth0.com/u/felix.seidl)\
**Post date:** [August 29, 2022, 7:02am UTC](https://community.auth0.com/t/oncontinuepostlogin-the-session-token-is-invalid-unexpected-token-payload-type/88757/3 "2022-08-29T07:02:08Z")

</div>

Hi @dan.woda,

Thanks for reaching out.

I’m using the ‘jose’ npm package to create the token on on the external site:

```auto
const secret = new TextEncoder().encode(shared_secret);
const jwt = await new jose.SignJWT({ state: stateParameter, favorite_color: "blue" }) // some dummy value
    .setProtectedHeader({ alg: 'HS256' })
    .setIssuedAt()
    .setSubject(userId)
    .setIssuer('***.azurewebsites.net')
    .setExpirationTime('1m')
    .sign(secret);

```

the redirect back to auth0:

```auto
window.location.replace(`https://***.eu.auth0.com/continue?state=${stateParameter}&token=${token}`);

```

onContinuePostLogin:

```auto
const payload = api.redirect.validateToken({
      secret: event.secrets.sharedsecret,
      tokenParameterName: "token",
    });

```

I have checked the token on [jwt.io](http://jwt.io) but saw no problems.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [August 30, 2022, 12:01am UTC](https://community.auth0.com/t/oncontinuepostlogin-the-session-token-is-invalid-unexpected-token-payload-type/88757/4 "2022-08-30T00:01:46Z")

</div>

Can you share (or DM) an example of the payload? This error suggests the payload is malformed.

---

<div class="post-metadata">

**Author:** ![felix.seidl](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/felix.seidl/32/12949_2.png) [@felix.seidl](https://community.auth0.com/u/felix.seidl)\
**Post date:** [August 30, 2022, 7:42am UTC](https://community.auth0.com/t/oncontinuepostlogin-the-session-token-is-invalid-unexpected-token-payload-type/88757/5 "2022-08-30T07:42:11Z")

</div>

I can reproduce this error with the payload from the example (`favorite_color: "blue"`)

---

<div class="post-metadata">

**Author:** ![bryanc](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/bryanc/32/39905_2.png) [@bryanc](https://community.auth0.com/u/bryanc)\
**Post date:** [September 14, 2022, 7:13pm UTC](https://community.auth0.com/t/oncontinuepostlogin-the-session-token-is-invalid-unexpected-token-payload-type/88757/6 "2022-09-14T19:13:12Z")

</div>

I also receive this same error, using the same code as above. I verified it on [jwt.io](http://jwt.io) as well. Any help here? The error message isn’t giving back any additional context.

---

<div class="post-metadata">

**Author:** ![miguelangelgalindez](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/miguelangelgalindez/32/42827_2.png) [@miguelangelgalindez](https://community.auth0.com/u/miguelangelgalindez)\
**Post date:** [January 20, 2023, 2:58am UTC](https://community.auth0.com/t/oncontinuepostlogin-the-session-token-is-invalid-unexpected-token-payload-type/88757/8 "2023-01-20T02:58:52Z")

</div>

You just need to set the **typ** header alongside the **alg** header. You will need something like this: `.setProtectedHeader({ alg: 'HS256', typ: 'JWT' })`

Then, your code would look like this:

```auto
const secret = new TextEncoder().encode(shared_secret);
const jwt = await new jose.SignJWT({ state: stateParameter, favorite_color: "blue" }) // some dummy value
    .setProtectedHeader({ alg: 'HS256', typ: 'JWT' })
    .setIssuedAt()
    .setSubject(userId)
    .setIssuer('***.azurewebsites.net')
    .setExpirationTime('1m')
    .sign(secret);

```

I know it’s too late, but I’m leaving the answer for anyone else struggling with this.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [January 20, 2023, 9:04am UTC](https://community.auth0.com/t/oncontinuepostlogin-the-session-token-is-invalid-unexpected-token-payload-type/88757/9 "2023-01-20T09:04:41Z")

</div>

Thanks for sharing that with the rest of community!

---

<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:** [February 3, 2023, 9:04am UTC](https://community.auth0.com/t/oncontinuepostlogin-the-session-token-is-invalid-unexpected-token-payload-type/88757/10 "2023-02-03T09:04:42Z")

</div>

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