Skip to content

Instantly share code, notes, and snippets.

Created April 24, 2013 07:56
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tfoldi/5450418 to your computer and use it in GitHub Desktop.
This ruby class can logon and invoke REST API URLs in Tableau server. Authentication is done by using RSA crpyto stuff.
require 'httpclient'
module TableauLDAPSync
class Tableau
def initialize(server_url)
proxy = ENV['HTTP_PROXY']
@http_client =
@http_client.debug_dev = STDOUT if $DEBUG
@server_url = server_url
def login(user, pass)
key =
# invoke /auth.xml on server
response = @http_client.get( tableau_url_with '/auth.xml' )
# parse returned XML
doc = response.body )
# read RSA key + authenticity token
authinfo = doc.elements[1, 'authinfo']
modulus = authinfo.elements[1, 'modulus']
exponent = authinfo.elements[1, 'exponent']
authenticity_token = authinfo.elements[1, 'authenticity_token']
# fill RSA key information
key.n = modulus.text.to_i(16)
key.e = exponent.text.to_i(16)
# logon to server with encrypted password
response = tableau_url_with('/auth/login.xml'),
{ 'authenticity_token' => authenticity_token.text,
'crypted' => assymmetric_encrypt(pass,key),
'username' => user
def tableau_url_with(path)
URI.join(@server_url, path)
# Encrypt test with RSA public key and pack as %.0x hex numbers
def assymmetric_encrypt(val, public_key)
crypt_binary = public_key.public_encrypt(val)
def get(path, params = {} )
@http_client.get( tableau_url_with(path), params)
def post(path, params = {} ) tableau_url_with(path), params)
Copy link

WarFox commented Feb 17, 2014

Hey thanks for the script.

I had to use

require 'rexml/document'

to get it working though.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment