Class: VIC::URLHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/vic/url_helper.rb

Class Method Summary collapse

Class Method Details

.generate(id_attributes) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/vic/url_helper.rb', line 11

def generate(id_attributes)
  params = id_attributes.traits
  params['timestamp'] = Time.now.utc.iso8601

  canonical_string = Oj.dump(params)
  params['signature'] = URLHelper.sign(canonical_string)
  {
    'url' => Settings.vic.url,
    'traits' => params
  }
end

.sign(canonical_string) ⇒ Object



23
24
25
26
# File 'lib/vic/url_helper.rb', line 23

def sign(canonical_string)
  digest = OpenSSL::Digest.new('SHA256')
  Base64.urlsafe_encode64(URLHelper.signing_key.sign(digest, canonical_string))
end

.signing_keyObject



28
29
30
# File 'lib/vic/url_helper.rb', line 28

def signing_key
  @key ||= OpenSSL::PKey::RSA.new(File.read(Settings.vic.signing_key_path))
end