4 Replies Latest reply on May 19, 2016 12:37 PM by Omar Manlapaz

    Request: Trusted Authentication node.js examples

    Kurt Fredericks

      Does anybody have any Trusted Authentication node.js code examples (specifically code which shows how to get a ticket) that they can share?


      I am trying to set up trusted authentication for a JavaScript application to retrieve certificates (via the node.js service) in order to interact with workbooks via the Tableau JavaScript API.


      I've seen examples shared for Java and .NET, but not for node.js (which is what I am currently limited to).


      Many thanks,


        • 1. Re: Request: Trusted Authentication node.js examples
          Ben Lower

          Kurt: Did you get this sorted out? Sorry that we don't have any sample code for you on this. If you are still stuck, can you provide a pointer to the Java sample code that shows what you want to do and I'll see what it might take to get a Node.js version.



          • 2. Re: Request: Trusted Authentication node.js examples
            Kurt Fredericks

            Thanks for the note, Ben.


            I haven't yet gotten to this, since we currently have a SAML connector, which generally works okay, but a Trusted Authentication solution would be preferable. I might have mixed up Java with C#/.NET in the examples I saw here:


            Trusted Authentication JavaScript Code Examples Required


            From the research I did previously, it didn't look like it would be too difficult to do. Once I get around to getting a working one going with node.js, I will share the code example here.



            • 3. Re: Request: Trusted Authentication node.js examples
              Ben Lower

              OK cool. I'm marking this as a discussion for now then since there's not a pressing question.

              • 4. Re: Request: Trusted Authentication node.js examples
                Omar Manlapaz

                I am looking for the same thing. Any status updates on finding examples for node js (server side) trusted authentication?


                Here is the JAVA sample (couldn't find anything for node.js though):


                package com.foo;



                import java.io.BufferedReader;

                import java.io.IOException;

                import java.io.InputStreamReader;

                import java.io.OutputStreamWriter;

                import java.net.URL;

                import java.net.URLConnection;

                import java.net.URLEncoder;



                import javax.servlet.ServletException;

                import javax.servlet.http.HttpServletRequest;

                import javax.servlet.http.HttpServletResponse;




                * Servlet implementation class for Servlet: TableauServlet



                public class TableauServlet extends javax.servlet.http.HttpServlet {

                    private static final long serialVersionUID = 1L;



                    public TableauServlet() {




                    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

                        final String user = "workgroupadmin";

                        final String wgserver = "localhost";

                        final String dst = "views/Book1/Sheet1";

                        final String params = ":embed=yes&:toolbar=yes";


                        String ticket = getTrustedTicket(wgserver, user, request.getRemoteAddr());

                        if ( !ticket.equals("-1") ) {


                            response.setHeader("Location", "http://" + wgserver + "/trusted/" + ticket + "/" + dst + "?" + params);



                            // handle error

                            throw new ServletException("Invalid ticket " + ticket);



                    // the client_ip parameter isn't necessary to send in the POST unless you have

                    // wgserver.extended_trusted_ip_checking enabled (it's disabled by default)

                    private String getTrustedTicket(String wgserver, String user, String remoteAddr)

                        throws ServletException


                        OutputStreamWriter out = null;

                        BufferedReader in = null;

                        try {

                            // Encode the parameters

                            StringBuffer data = new StringBuffer();

                            data.append(URLEncoder.encode("username", "UTF-8"));


                            data.append(URLEncoder.encode(user, "UTF-8"));


                            data.append(URLEncoder.encode("client_ip", "UTF-8"));


                            data.append(URLEncoder.encode(remoteAddr, "UTF-8"));


                            // Send the request

                            URL url = new URL("http://" + wgserver + "/trusted");

                            URLConnection conn = url.openConnection();


                            out = new OutputStreamWriter(conn.getOutputStream());




                            // Read the response

                            StringBuffer rsp = new StringBuffer();

                            in = new BufferedReader(new InputStreamReader(conn.getInputStream()));

                            String line;

                            while ( (line = in.readLine()) != null) {




                            return rsp.toString();


                        } catch (Exception e) {

                            throw new ServletException(e);


                        finally {

                            try {

                                if (in != null) in.close();

                                if (out != null) out.close();


                            catch (IOException e) {}