Enabling authenticated visitors in Web Widget (Classic)

Return to top

19 Comments

  • David Berumen

    Hi, @... could you provide us with a complete downloadable example of this topic with php.
    please.

     
    0
  • Dave Dyson
    Zendesk Community Manager

    Hi David,

    Did you see the download link in the PHP section above? PHP

    0
  • David Berumen

    hi,@....

    yeah I'm very confused by now, I did all the steps and it still doesn't work. so request the downloadable I think it will help us all.

    0
  • Dave Dyson
    Zendesk Community Manager

    @... Here's the link from above: PHP-JWT

    0
  • Andrew Reid

    Hi Ramin Shokrizadeh thanks for this guide. After implementing the changes described, we're experiencing some odd behaviour. The user appears to be authenticated and sees their readonly profile information as expected. However, upon clicking the 'Start Chat' button, the following error message is displayed:

    There are no network or console errors visible in the browser, and when the logic in `webWidget.authentication.chat.jwtFn` is removed, the unauthenticated chat works as expected. Any insights into how to resolve this would be much appreciated!

    Edit:
    I have seen this article on this error message and have confirmed the 2 causes identified there are not applicable here.

    0
  • Ramin Shokrizadeh
    Zendesk Product Manager

    Andrew Reid Thanks for letting us know about the issue you are experiencing. Can you please reach out to our advocacy team with the link to where the widget is located and authenticating visitors so we can have a look at what is going on with your implementation? 

    0
  • Andrew Reid

    Thanks Ramin Shokrizadeh! We were able to identify the problem. In case it's helpful for anyone else, when adding the authentication logic we forgot to remove an existing usage of the identify command. After removing that, the authenticated user was able to start the chat without issue.

    0
  • moment long

    I would like to ask how to continuously call the jwtFn method to update the token
    This is the code I added when I initialised it
    I am a single page application, how can I do this by calling the jwtFn method after login.

    0
  • DJ Buenavista Jr.
    Zendesk Customer Care
    Hi Moment Long,
     
    Thank you for reaching out to Zendesk Support.
     
    In regards to your question, were you able to check the provided example above for the JTW token method? In the example above, it was mentioned the following line that you need to use in order to call the jtwFn multiple times. 
     
    jwtFn: function(callback) { 
             fetch('JWT_TOKEN_ENDPOINT').then(function(res) {
                res.text().then(function(jwt) {
                 callback(jwt);   

    Thank you and have a wonderful day ahead!
     
     
    Kind regards,
     
    0
  • Espartan Code

    Where can I find an example of javascript to authenticate the user in the chat I'm still going around in the answers that give me an example here

    0
  • Alessandro Battistini

    Hi Espartan Code,

    You can see the example on this article as mentioned in the following part:

    Use the zESetting Javascript API with the key `webWidget.authentication.chat.jwtFn` to provide a function which supplies a fresh JWT every time it is invoked. Below is a code example:

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

    Hi,

    do we have an example what JWT_TOKEN_ENDPOINT should look like?
    I am after whether it's POST or GET ?

    what is the response looks like e.g. JSON or text? what content-type ?

    thank you

    0
  • Tim O'Mahony

    Following Wedy Chainy question:

    in “Creating JWT Token”, it shows a snippet
    window.zESettings = {
        webWidget: {
            authenticate: {
                 chat: {
                 jwtFn: function(callback) {
                 fetch('JWT_TOKEN_ENDPOINT').then(function(res) {
                 res.text().then(function(jwt) {
                 callback(jwt);
                 });
             });
        }
      }
     }
    }
    };
    but there’s no explanation of what is JWT_TOKEN_ENDPOINTwhat expectation here, is it POST / GET ? what is the request content-type, and what is the response content-type, and what the expecting response look like?If anyone has done this before/examples, any pointers here would be great!
    0
  • Dainne Lucena
    Zendesk Customer Care

    Hi Wedy Chainy & Tim O'Mahony,

    This documentation is actually meant to be relayed to the developers of your team, as this is not beginner documentation since it requires programming skills. Rest assured that if this is relayed to the devs, they'd have everything they need.

    But to clarify, even if we "fetch", this simply means that the token can be returned by a Javascript function or returned by an external page & its code logic as written in the doc

    In the example above, JWT_TOKEN_ENDPOINT is an endpoint which can be implemented on your own server to obtain a fresh JWT

     
    Fetch as it means, is always some kind of "GET" method, but here HTTP request methods (GET, POST, PUT, and DELETE) are not relevant as fetch is a method in JavaScript https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch 
     
    This is also not related to content-type as we expect that JWT_TOKEN_ENDPOINT returns the token string when calling it. 
     
    A JWT token string would look something like this
     
    Ex :
    Here are 2 screenshots from my colleague's implementation using PHP using Firebase
     
    Fetch endpoint :

    JWT generating :
    Hope this helps!

    0
  • Jimmy McDermott

    Hi! This is helpful, thanks. If the user's external_id is already in the Zendesk system as an end-user, two questions:

    1. Will it recreate the user? (I am guessing not) 

    2. Will this enable the user to receive articles that are scoped to the user's tags and therefore user segments? 

    Thanks! 

    0
  • Hey!

    Can we somehow send the client's phone number to Zendesk using JWT?

    Our employees use Zendesk to receive calls, but the call history is stored separately from the chat history, because the "chat client" and the "call client" are two different entities.
    We need Zendesk to understand that the person who is calling now and the person who was chatting 5 minutes ago are the same client.
    In this case, we believe that the call history and chat history will be tied to the same entity, and our employees will work with a single communication history.

    1
  • Fellipe M.
    Zendesk Customer Care
    Hi Вячеслав,
     
    According to the article Anatomy of a JWT request, it is possible to pass a Phone Number is a JWT request. You just need to ensure that the phone number is in an accepted format as described here.
    If you have any difficulties, feel free to raise a ticket with the Support team and we'll be happy to assist you further.
     
    Best,
    0
  • Pavel Glac

    Hi!

    Have following error

    JWT token which is sended looks ok

    Don't understand the error message and looks like a problem and your side bcs secret token you should already have. Do you have idea where could be the problem?

    thank you

    0
  • Jeff C
    Zendesk Customer Care

    Hey Pavel,

    Can you please double check if you are using the Shared Secret from the Chat dashboard and not from the Web Widget settings? This one common issue where the shared secret being used is not the correct one.

    If you have confirmed that you are using the Shared Secret from Chat and have also tried regenerating a new one but still does not work, please reach out to us via Messaging or Option 2 listed here so we can assist you further.

    0

Please sign in to leave a comment.

Powered by Zendesk