require 'cgi'
require 'securerandom'
require 'uri'
require 'base64'
require 'json'
require 'openssl'
module LookerEmbedClient
def self.my_secret()
return 'e6e6bed97dc7a4e24370d2ef41acada80dddd659d463e2d6c29bdd28bab2cdad'
end
# User Parameters:
external_user_id = "100"
first_name = "Jake"
last_name = "Yoos"
permissions = ['see_user_dashboards', 'see_lookml_dashboards', 'access_data', 'see_looks']
models = ['powered_by']
access_filters = {:powered_by => {:'products.brand' => "Allegra K"}}
# System Wide Parameters:
host = 'demonew.looker.com'
secret = my_secret()
session_length = 15 * 60
force_logout_login = true
# Other Settings:
embed_url = "/embed/sso/dashboards/234"
# user options
json_external_user_id = external_user_id.to_json
json_first_name = first_name.to_json
json_last_name = last_name.to_json
json_permissions = permissions.to_json
json_models = models.to_json
json_access_filters = access_filters.to_json
# url/session specific options
embed_path = '/login/embed/' + CGI.escape(embed_url)
json_session_length = session_length.to_json
json_force_logout_login = force_logout_login.to_json
# computed options
json_time = Time.now.to_i.to_json
json_nonce = SecureRandom.hex(16).to_json
# compute signature
string_to_sign = [host, embed_path, json_nonce, json_time,
json_session_length, json_external_user_id, json_permissions,
json_models, json_access_filters].join("\n")
signature = Base64.encode64(
OpenSSL::HMAC.digest(
OpenSSL::Digest.new('sha1'),
secret,
string_to_sign.force_encoding("utf-8"))).strip
# construct query string
query_params = {
nonce: json_nonce,
time: json_time,
session_length: json_session_length,
external_user_id: json_external_user_id,
permissions: json_permissions,
models: json_models,
access_filters: json_access_filters,
first_name: json_first_name,
last_name: json_last_name,
force_logout_login: json_force_logout_login,
signature: signature
}
query_string = URI.encode_www_form(query_params)
puts "https://#{host}#{embed_path}?#{query_string}"
end
This code writes a URL which calls content from a Looker instance. This URL is embedded in an iframe to allow authenticated access to Looker content. For more information see https://looker.com/platform/powered-by
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.