Module: FastComments::SSO::Helpers

Defined in:
lib/fastcomments/sso/helpers.rb

Class Method Summary collapse

Class Method Details

.create_verification_hash(api_key, timestamp, user_data_json_base64) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fastcomments/sso/helpers.rb', line 8

def self.create_verification_hash(api_key, timestamp, user_data_json_base64)
  # Create message string by concatenating timestamp and base64 data
  message_str = "#{timestamp}#{user_data_json_base64}"

  # Create HMAC using SHA256 hash function
  mac = OpenSSL::HMAC.digest('SHA256', api_key, message_str)

  # Get digest as bytes then convert to hex
  get_bytes_as_hex(mac)
rescue => e
  raise CreateHashError, "Failed to create verification hash: #{e.message}"
end

.get_bytes_as_hex(bytes_data) ⇒ Object



21
22
23
# File 'lib/fastcomments/sso/helpers.rb', line 21

def self.get_bytes_as_hex(bytes_data)
  bytes_data.unpack1('H*')
end