forked from TheOdinProject/theodinproject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
moot_auth_test.rb
34 lines (29 loc) · 1.04 KB
/
moot_auth_test.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
require 'digest/sha1'
require 'base64'
require 'json'
# timestamp (in seconds). Improves security.
timestamp = Time.now.to_i
# SSO object contains the user information, where
#
# - id identifies the user. A different id represents a different user
# - displayname is the full name
# - is_admin, `true` gives administrative rights.
sso = {
:user => {
:id => 'johndoe', # required
:displayname => 'John Doe', # required
:email => 'john.doe@gmail.com',
:avatar => '//gravatar.com/avatar/e5fb96fe7ec4ac3d4fa675422f8d1fb9',
:is_admin => true,
}
}
# The SSO object as base64 encoded string. Not readable by humans.
message = Base64.strict_encode64 sso.to_json
# The SSO object is coupled with a hashed signature. This must always be
# generated on the server since the provided secret key should not be seen
# by anyone else but you.
signature = Digest::SHA1.hexdigest "testapisecretkey #{message} #{timestamp}"
# Output the values
puts "timestamp: #{timestamp}"
puts "signature: #{signature}"
puts "message: #{message}"