9 Replies Latest reply on Jul 4, 2013 4:53 AM by Russell Christopher

    get trust ticket by ajax

    Tony Ma

      How can I get trust ticket by ajax?

       

      I am using MVC 4 .NET Framework 4.5.

       

      want to get the trust ticket by using Ajax

        • 1. Re: get trust ticket by ajax
          Russell Christopher

          Hi Tony -

           

          All you need to do is POST a request to Tableau server via AJAX. You'll post to http://servername/trusted with POST parameters of username=<whatever user to get a ticket for> 

           

          That being said, this isn't a great idea. If you are doing this work from the browser Tableau Server needs to trust the IP address of the machine on which the browser is running. Normally, you're going to POST from a "trusted" app server, not from a web browser sitting on an arbitrary ip address.

          • 2. Re: get trust ticket by ajax
            Tony Ma

            Hi there,

             

            I used following Javascript code to receive the trusted ticket. However it's not working. what's the problem here?

             

             

            $(document).ready(function () {

                $("div.tableau").each(function () {

                    var workbook = $(this).attr("data-tableau-workbook");

                    var view = $(this).attr("data-tableau-view");

                    var userame = $(this).attr("data-tableau-userame");

                    var ticket;

             

                    $.ajax({

                        type: 'POST',

                        url: "http://hostIp/trusted",

                        data: { username: username },

                        success: function (result) {

                            alert('Ok');

                            ticket = result;

                        },

                        error: function () { alert('Error'); }

                    });

             

                    var url = "http://hostIp/trusted/" + ticket + "/views/" + workbook + "/" + view;

             

                    var options = {

                        width: this.offsetWidth,

                        height: this.offsetHeight,

                        hideTabs: true,

                        hideToolbar: false,

                        onFirstInteractive: function () {

                            workbook = viz.getWorkbook();

                            activeSheet = workbook.getActiveSheet();

                        }

                    };

                    viz = new tableauSoftware.Viz(this, url, options);

                });

            });

            • 3. Re: get trust ticket by ajax
              Tony Ma

              only Ajax part are not working. the rest code are tested.

              • 4. Re: get trust ticket by ajax
                Russell Christopher

                Questions:

                 

                • Forget your code for a moment - are you sure trusted tickets is actually functioning on the server? Have you used the Tableau KB article on how to test it? Your code might be fine, actually.
                • Have you put your code under a debugger to see what values the variables contain? Could you add some error handling to alert() or console.log? Without this information it's going to be pretty difficult for anyone here to give you guidance.
                • 5. Re: get trust ticket by ajax
                  Tony Ma

                  The tableau server and the web server is running fine. we have a running website with trusted authentication connection between tableau server and web server.

                   

                  I found the sample code for request trusted ticket in Java, PHP, Ruby, but not Javascript..

                   

                  If you can simply send me a sample code for getting the trusted ticket from tableau server in Javascript, that will be very helpful.

                  • 6. Re: get trust ticket by ajax
                    Russell Christopher

                    Tony,  the approach you are taking is dangerously insecure because you're using a client-side technique for requesting tickets - tickets should only be requested by a trusted server-side resource.

                     

                    In order for "your" technique to work, Tableau Server must be configured to trust each and every IP address your clients run their browser from. Once Tableau Server is told to trust an address, anyone on that IP address can craft a simple POST to get a trusted ticket for ANY user on the server. You don't want this, Instead, the post should come from a Server-side process - Java, PHP, Ruby, ASP.NET (executed on the server)

                     

                    The reason why we don't supply sample JavaScript code to do this work is because it's a bad idea. Sorry - not trying to be a troll or anything - just want to keep you out of trouble

                    • 7. Re: get trust ticket by ajax
                      Tony Ma

                      OK, I think I got your point.

                       

                      What I am doing now is using a ajax to request a action from server, and the action on the web server will request the ticket from tableau server. And it's working fine.

                       

                      Thanks for your help.

                      • 8. Re: get trust ticket by ajax
                        Gabriel Queiroz

                        Tony, we are looking for the same solution you have described and according to your last post "it is working fine".

                         

                        Could you share the code with us?

                         

                        Our main objective is get a ticket using java script and ajax.

                         

                        Thank you in advance, Gabriel