1

I need to display user's name in the in the zendesk chat ( for the agents), I'm using the code provided by zendesk:

window.zESettings = {
 webWidget: {
   authenticate: {
     chat: {
       jwtFn: function(callback) { 
         fetch('JWT_TOKEN_ENDPOINT').then(function(res) {
            res.text().then(function(jwt) {
             callback(jwt);
            });
          });
        }
      } 
    }
  }
};

and jwt token is:

var payload = {
  name: '#{customerName}',
  email: '#{customerEmail}',
  iat: #{timestamp},
  external_id: '#{externalId}'
};
var token = jwt.sign(payload, '#{yourSecret}');

The code doesn't work, I don't get errors but user name is not visible. Zendesk documentation doesn't provide any valuable information, has anyone integrated Zendesk in their app? What am I doing wrong? any help and suggestion is greatly appreciated.

alia
  • 168
  • 1
  • 3
  • 15
  • did you find the solution? During the integration I faces with similar issue, I did all the steps described here https://support.zendesk.com/hc/en-us/articles/4408838925082 but at the end just response: { "success": false, "error": "not entitled to visitor auth" } – Nazar Mandzyk Mar 04 '23 at 00:38

2 Answers2

0

I'm running into some issues with a similar implementation. In my situation I am using the same Javascript to authenticate the chat webWidget. I have my JWT_TOKEN_ENDPOINT defined in a rails controller (RoR) which uses the ruby-jwt gem to generate the token.

In my case though, my browser is showing the error message:

Zendesk Chat Web SDK: Error: init: Failed to verify token: jwt verification error

Are you seeing any browser console errors to suggest what might be the issue?

Do you have your endpoint setup to generate the JWT token?

Are you passing a valid shared secret in the jwt.sign(payload, "#{youSecret}") var assignment?

0

Make sure that timestamp is in seconds, without floating points.

Use iat: Math.round(Date.now() / 1000)