Zendesk returns 401 when using messenger loginUser functionality | Community
Skip to main content

Zendesk returns 401 when using messenger loginUser functionality

  • October 26, 2023
  • 9 replies
  • 0 views

Vitalii14

I created zendesk account and generated jwt at admin center in Account > End user authentication. Added "script" tag generated by zendesk to my website and executed 

zE("messenger", "loginUser", function (callback: (jwt: string) => void) {
callback("token");
});

on page initialization. Here is the jwt payload

{
"name": "name",
"email": "email@team.co",
"external_id": "904543952",
"scope": "user",
  "iat": 1698322052,
  "exp": 1698325652
}

The algorithm is HS256. And it still returns me 401 on /login request.

What did i do wrong?

 
 
 

9 replies

Tipene
  • October 26, 2023

Hey Vitalii,

One quick thing to check before we troubleshoot this in more detail: in the callback function, it looks like you're passing a string "token". Can you double check your code to ensure that the correct token variable is being passed.

If you continue to run in to problems, let me know and we can look in to the issue further.

Thanks!

Tipene


Vitalii14
  • Author
  • October 26, 2023

Hey, Tipene!

Currently i'm doing it as simply as it can be so in fact in my code i just literally post token as string in 'callback', no any variables there.

Thanks!


Tipene
  • October 26, 2023
Thanks for clarifying that!
 
Can you also double check that the shared_secret and kid are correct, and being passed correctly? The kid should be in your headers object and the shared_secret should be sent in the jwt.sign method.

Vitalii14
  • Author
  • October 26, 2023

Double checked, everything's fine with that.


Tipene
  • October 26, 2023

Okay, great. Do you have a repo or somewhere I can take a look at your code? It'd be helpful to see exactly whats happening


Vitalii14
  • Author
  • October 26, 2023

I created one here. https://github.com/Skrpk/zendesk_text

Go to pages/_app.tsx - there will be frontend logic with applying jwt to callback.

Go to pages/api/auth - there is logic of jwt generation.


Tipene
  • October 26, 2023
Thanks for this! I don't see the alg and typ values being defined and passed in header object in the jwt.sign method. Can you add those and see if it works?

Vitalii14
  • Author
  • October 26, 2023

This values for header are generated automatically by jsonwebtoken npm lib on backend. 

Here is screenshot of generated token decrypted


Tipene
  • October 26, 2023

Yeah you're right. I thought that this was causing a 401 on my end while testing but it was something else unrelated. I'm going to pull this in to a ticket so I can take a look at your account on the Zendesk side. You should see an email come through from me shortly!