Class: Grnds::Looker::Hmac::SignedUrlGenerator
- Inherits:
-
Object
- Object
- Grnds::Looker::Hmac::SignedUrlGenerator
- Defined in:
- lib/grnds/looker/hmac.rb
Instance Method Summary collapse
- #getUrl ⇒ Object
-
#initialize(config) ⇒ SignedUrlGenerator
constructor
A new instance of SignedUrlGenerator.
Constructor Details
#initialize(config) ⇒ SignedUrlGenerator
Returns a new instance of SignedUrlGenerator.
13 14 15 16 |
# File 'lib/grnds/looker/hmac.rb', line 13 def initialize(config) ENV['LOOKER_EMBED_SECRET'] || raise('no LOOKER_EMBED_SECRET provided') @config = config end |
Instance Method Details
#getUrl ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/grnds/looker/hmac.rb', line 18 def getUrl() secret = ENV['LOOKER_EMBED_SECRET'] json_external_user_id = @config[:external_user_id].to_json json_first_name = @config[:first_name].to_json json_last_name = @config[:last_name].to_json = @config[:permissions].to_json json_models = @config[:models].to_json json_access_filters = @config[:filters].to_json json_user_attributes = @config[:user_attributes].to_json path = @config[:path_root] + CGI.escape(@config[:embed_path]) json_session_length = (@config[:session_length] || 86400).to_json json_force_logout_login = true.to_json json_current_time = Time.now.to_i.to_json json_nonce = SecureRandom.hex(16).to_json string_to_sign = '' string_to_sign += @config[:host] + "\n" string_to_sign += path + "\n" string_to_sign += json_nonce + "\n" string_to_sign += json_current_time + "\n" string_to_sign += json_session_length + "\n" string_to_sign += json_external_user_id + "\n" string_to_sign += + "\n" string_to_sign += json_models + "\n" string_to_sign += json_user_attributes + "\n" string_to_sign += json_access_filters signature = Base64.encode64( OpenSSL::HMAC.digest( OpenSSL::Digest.new('sha1'), secret, string_to_sign.force_encoding('utf-8'))).strip query_params = { nonce: json_nonce, time: json_current_time, session_length: json_session_length, external_user_id: json_external_user_id, permissions: , models: json_models, access_filters: json_access_filters, user_attributes: json_user_attributes, first_name: json_first_name, last_name: json_last_name, force_logout_login: json_force_logout_login, signature: signature } query_items = [] query_params.each_pair do |k,v| query_items << k.to_s + "=" + CGI.escape(v) end query_string = query_items.join('&') "https://" + @config[:host] + path + '?' + query_string + "\n" end |