Enabling authenticated visitors in Web Widget (Classic)

Return to top

31 Comments

  • David Berumen

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

    0
  • Dave Dyson

    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

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

    0
  • Andrew Reid

    Hi@...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 seenthis articleon this error message and have confirmed the 2 causes identified there are not applicable here.

    0
  • Ramin Shokrizadeh
    Zendesk Product Manager

    Andrew ReidThanks for letting us know about the issue you are experiencing. Can you pleasereach out to our advocacy team与小部件的位置和一个链接uthenticating visitors so we can have a look at what is going on with your implementation?

    0
  • Andrew Reid

    Thanks@...! 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 theidentify 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
    Zendesk Employee

    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

    FollowingWedy Chainyquestion:

    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

    HiWedy 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 JavaScripthttps://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.

    JWT标记字符串会看起来像这样

    Ex :
    Here are 2 screenshots from my colleague's implementation using PHP using Firebase

    Fetch endpoint :

    JWT generating :
    Hope this helps!

    0
  • Jimmy McDermott

    嗨!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 articleAnatomy of a JWT request, it is possible to pass aPhone Numberis a JWT request. You just need to ensure that the phone number is in an accepted format as describedhere.
    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

    嗨!

    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,

    请双重检查如果您使用年代hared 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.

    如果你已经确认你使用的是共享d 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 listedhereso we can assist you further.

    0
  • Marcin Wolniewicz

    嗨!我努力得到这个工作。我能看到that the chat is making one request to my endpoint, but never another one. Also in the Agent's view there are no user details or verification. Does the algorthim need to be HS256? I found that information in your other guide, but not here so I'm a bit confused:https://support.zendesk.com/hc/en-us/articles/4408836328346

    Is there any way to troubleshoot this issue? Maybe the there is some problem with decoding/encoding?

    EDIT:my problem was fixed after changing the algorithm to HS256, adding the "typ":"JWT" header and parsing "external_id" to string (I was sending it as a number before). Not sure which of these changes did the trick, since I released all three together, but now it works

    0
  • Kevin Kim

    Hello, I see that when we authenticate our users using the new Messaging API, the user's external_id will show up on their profilehttps://developer.zendesk.com/documentation/zendesk-web-widget-sdks/sdks/web/enabling_auth_visitors/

    However, when I authenticate our users through the Classic SDK, though we get the user's email and name, the external_id that we provided to get the JWT token is nowhere to be found. Is there a way to get the external ID somehow?

    0
  • Arin Mukhrjee

    *** URGENT HELP needed***

    Hello, Trying to implement the Zendesk widget on javascript on my application with authentication.

    the API to return JWT it is being properly called as i can see from the JS.

    The JWT returned is as below :-

    But i keep getting below error on my network tab on browser when widget tries to call zendesk. Any help is appreciated.

    {
    "success": false,
    "error": "failed to validate claims"
    }
    here is the javascript :-
    0
  • Viktor Osetrov
    Zendesk Customer Care
    Hi Arin,

    Thanks for your question.

    The issue with 400 Bad Requests or failed to validate claims error seems to be related to your values.
    Please make sure that you are usingseconds (not milliseconds)for bothiatandexp.

    iatandexp: Integer value of the current timestamp, inseconds.
    Some functions in specific languages i.e. JavaScript's Date.now() return milliseconds, so please make sure you convert to seconds.

    Hope it helps
    0
  • Arin Mukhrjee

    ThanksViktor Osetrovfor the prompt response, highly appreciate it. So i am using JAVA rest API to generate the JWT and i am using below to generate the time in seconds. Any ideas if anything else you might think of is the issue possibly?

    Also to add, I have tried with and without both base64 encoding the secret, same error message.

    I still do not include the 'jti' as part of the claim as I read a few documentations.

    Please advise.

    java.time.Instant.now().getEpochSecond()
    0
  • Viktor Osetrov
    Zendesk Customer Care
    Hi Arin,

    Thanks for your quick reply. I still believe that the issue is related to values.
    Could you please check"name"and"email"?

    It looks like you are using the same value twice:

    Hope it helps,

    0
  • Arin Mukhrjee

    HeyViktor Osetrov, appreciate you responding on my stuck issue. Please see below my updated JWT payload here , and I do have different name and email. Just re-iterating, i have tried with using the secret as Base64 encoded and without it as well, keep getting

    "error": "failed to validate claims". Anything else, that you may think of ?
    Your continued help is highly appreciated and I thank you in advance.

    .

    0
  • Remi
    Zendesk Customer Care

    Good day,Arin Mukhrjee,

    Thank you for your continuous patience on this matter, hope you are doing well today!

    To answer this, you cannot use attributes that are not meant to be used against our login endpoint, as we have some kind of model validator for your JWT operating in our backend.

    Thus, as per your screenshot, attributes nor being part of the example provided will invalidate your payload.

    Remember, for JS or any programming language to respect the example provided :

    name: '#{customerName}', email: '#{customerEmail}', iat: #{timestamp}, external_id: '#{externalId}'

    I personally use it for PhP and here is how I build my payload :

    And it works like a charm!

    • Example of a valid JWT payload :
    eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYW1lIjoiUmVtaSBTYXVtZXQiLCJlbWFpbCI6InJzYXVtZXRfemVuZGVza0BvdXRsb29rLmNvbSIsImlhdCI6MTY2ODQyMjczMCwiZXh0ZXJuYWxfaWQiOiI4In0.4u9HZPEeVdA11_lIdYGdCvne0uTMGcDsvC_UnrpLXQQ



    PS: Remember for theexternal_idiattribute :

    once set for the customer, this value cannot be changed. We recommend that you use your system's unique user id for this field. For example, user-123456

    Hope this clarifies it! Have a great rest of your day.

    Best regards,

    0
  • webmaster groupgia

    Hello good morning,

    I am trying to send all the information to the chat but it does not work, I access the intranet from another computer and the history appears empty starting a new conversation

    The code is the following:

    window.zESettings = {
    webWidget: {
    authenticate: {
    chat: {
    jwtFn: function(callback) {
    fetch(localStorage["ChatToken"]).then(function(res) {
    res.text().then(function(jwt) {
    callback(jwt);
    });
    });
    }
    }
    }
    }
    };



    And the code on the server is the following:

    $payload = [
    'name' => $nombrecliente ,
    'email' => $email,
    'external_id' => $ID,
    'iat' => time(),
    'nbf' => 1357000000
    ];

    $key = '**';


    /**
    * IMPORTANT:
    * You must specify supported algorithms for your application. See
    * https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40
    * for a list of spec-compliant algorithms.
    */
    $jwt = JWT::encode($payload, $key, 'HS256');

    This should make our client see his chat history when accessing the intranet, is that correct?

    0
  • Remi
    Zendesk Customer Care

    Good daywebmaster groupgia,

    Thank you for your post, hope you are doing well!

    Indeed, as outlined, if your authentication is successful, you should be able to view the past interaction's history for your Visitor :

    Finally, the authenticated visitor will have the ability to see their past conversations in the widget by scrolling up in the chat log. To learn about conversation history support for authenticated visitors, clickhere.

    I ran a test on my personal PhP authentication for Chat and can confirm if I initiate a Chat on computer 1 and then end up the Chat, go on computer 2 and login my Visitor, I can access the past interaction that I just wrapped up on computer 1.

    Are you able to confirm your authentication is successful? One marker is simply to make sure the green dot is present when your Visitor chats you in, for example :

    And here we can see, within the widget, the past interaction and the new one when my Visitor is authenticated.

    • Red frame > interaction from computer 1 (Chat ended)
    • Blue frame > interaction from computer 2 (new Chat)

    Let me know if you are still not able to make this work or if you are not able to authenticate your users, as we may need to turn this into a ticket to investigate it further.

    But be reassured, I can confirm the feature works.

    Have a great rest of your day!

    Best regards,

    0
  • BAKO

    Hello,

    We have enabled this feature recently and receiving authenticated user chats.

    I have 2 questions;

    If I wanted to report on just authenticated visitor chats, is there a way to filter those out in Explore or some other form of reporting? I thought about adding a tag to these chats as they start but couldn't figure out how.

    Secon questions is; If I wanted to create a trigger for these authenticated user chats, what conditions can I use? Or is there even a native option for it?

    Regards.

    0

Pleasesign into leave a comment.

Powered by Zendesk