Cannot authenticate visitors with the Web SDK | Community
Skip to main content

Cannot authenticate visitors with the Web SDK

  • February 26, 2019
  • 6 replies
  • 0 views

I'm trying to use the sample Chat Web SDK app found here https://github.com/zendesk/zopim-chat-web-sdk-sample-app using authentication. I was able to setup the example without authentication but when I use the code found here: https://api.zopim.com/web-sdk/#visitor-authentication in order to authenticate 

zChat.init({
    account_key: 'YOUR_ZENDESK_CHAT_ACCOUNT_KEY',
    authentication: {
        jwt_fn: function(callback) {
            fetch('JWT_TOKEN_ENDPOINT').then(function(res) {
                res.text().then(function(jwt) {
                    callback(jwt);
                });
            });
        }
    }
});

I see the following on the console log:


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

The call to: https://id.zopim.com/authenticated/web/jwt returns

{
"success": false,
"error": "failed to validate claims"
}

I know that Im generating the JWT correctly, as I use the same logic for the Zendesk Support SDK and it works. Also, when I validate the token here: https://jwt.io/ it verifies the secret signature and the contents are correct.

The only difference is that for simplicity I'm generating the token inside the jwt_fn instead of calling and endpoint, but that shouldn't be a problem for testing purposes.

Any idea of what I could be missing?

Thanks!!

 

 

 

This topic has been closed for replies.

6 replies

  • February 27, 2019

Hi Gabriel,

Can you tell me where you are getting the secret from? It sounds like you may be using the wrong secret.

Can you go into the Chat dashboard and Settings --- Widget --- Widget security and use the shared secret from there?

Thanks,

Ramin


  • Author
  • February 27, 2019

Hi Ramin,

That's where I'm getting the secret from (It's a different one from the one I generated for the Support SDK). The url I'm getting it from is: http://[SUBDOMAIN].zendesk.com/chat/agent#widget/widget_security

Thanks!

Gabriel.


  • February 27, 2019

Hi Gabriel,

Thanks for the addition information. Can you share a link to the page where the custom widget is located so we can troubleshoot further? 

Thanks,

Ramin


  • Author
  • February 27, 2019

Hi Ramin,

I've uploaded the demo here, it takes a bit to load: https://zendeskchat.herokuapp.com/

I tested it and it works when I disable authentication.

Thanks for the help.

Gabriel


  • February 28, 2019

Hi Gabriel,

Seems like your iat and exp values are not integers, which would be causing this problem. It expects integer values in the call.

-Ramin


  • Author
  • February 28, 2019

Thanks Ramin! That was the issue. It's working now.

Best!

Gabriel.