Class: SmileIdentityCore::Signature

Inherits:
Object
  • Object
show all
Defined in:
lib/smile-identity-core/signature.rb

Overview

Contains handy methods to generate and confirm signature for authentication

Instance Method Summary collapse

Constructor Details

#initialize(partner_id, api_key) ⇒ Signature

Returns a new instance of Signature.



6
7
8
9
# File 'lib/smile-identity-core/signature.rb', line 6

def initialize(partner_id, api_key)
  @api_key = api_key
  @partner_id = partner_id
end

Instance Method Details

#confirm_signature(timestamp, msg_signature) ⇒ Boolean

Confirms the signature against a newly generated signature based on the same timestamp

Parameters:

  • timestamp (String)

    the timestamp to generate the signature from

  • msg_signature (String)

    a previously generated signature, to be confirmed

Returns:

  • (Boolean)

    TRUE or FALSE



27
28
29
# File 'lib/smile-identity-core/signature.rb', line 27

def confirm_signature(timestamp, msg_signature)
  get_signature(timestamp)[:signature] == msg_signature
end

#generate_iso_timestamp_signature(timestamp = Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%LZ')) ⇒ Object



18
19
20
# File 'lib/smile-identity-core/signature.rb', line 18

def generate_iso_timestamp_signature(timestamp = Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%LZ'))
  get_signature(timestamp)
end

#generate_signature(timestamp = Time.now.to_s) ⇒ Hash

Generates a signature based on the specified timestamp (uses the current time by default)

Returns:

  • (Hash)

    containing both the signature and related timestamp



14
15
16
# File 'lib/smile-identity-core/signature.rb', line 14

def generate_signature(timestamp = Time.now.to_s)
  get_signature(timestamp)
end