-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.rb
55 lines (43 loc) · 1.29 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
require 'sinatra'
require 'haml'
require 'time'
require 'digest'
set :port, 8080
ENDPOINT = 'https://example.widencollective.com/login/simple'
SHARED_SECRET = rand(36**8).to_s(36)
get '/' do
haml :app
end
get '/post' do
@endpoint = ENDPOINT
@fields = userFields()
haml :post
end
get '/get' do
queryParams = userFields().map { |k,v| "#{k}=#{v}" }.join('&')
@endpointWithParams = "#{ENDPOINT}?#{queryParams}"
haml :get
end
def userFields
fields = {
:timestamp => Time.now.httpdate,
:guid => '123456789',
:email => '[email protected]',
:first_name => 'Example',
:last_name => 'User',
:roles => 'General Role'
}
puts "fields = #{fields}"
# Calculating the signature...
# First join all the field values without a delimiter (in ascending order by key)
fieldString = fields.sort_by { |key| key }.to_h.map { |k,v| v }.join('')
puts "fieldString = #{fieldString}"
# Append the shared secret to the joined field String
fieldStringWithSharedSecret = fieldString + SHARED_SECRET
puts "fieldStringWithSharedSecret = #{fieldStringWithSharedSecret}"
# Calculate md5 hash of the field String with shared secret
signature = Digest::MD5.new.update(fieldStringWithSharedSecret).hexdigest
puts "signature = #{signature}"
fields[:signature] = signature
fields
end