Class: TrainPlugins::Rest::HmacSignature

Inherits:
AuthHandler show all
Defined in:
lib/train-rest/auth_handler/hmac-signature.rb

Overview

Authentication via HMAC Signature.

Instance Attribute Summary

Attributes inherited from AuthHandler

#connection, #options

Instance Method Summary collapse

Methods inherited from AuthHandler

#auth_headers, #auth_parameters, descendants, #initialize, #login, #logout, name, #process_error, #renew_session, #renewal_needed?

Constructor Details

This class inherits a constructor from TrainPlugins::Rest::AuthHandler

Instance Method Details

#check_optionsObject

Raises:

  • (ArgumentError)


7
8
9
10
11
12
# File 'lib/train-rest/auth_handler/hmac-signature.rb', line 7

def check_options
  raise ArgumentError.new("Need :hmac_secret for HMAC signatures") unless options[:hmac_secret]

  options[:header] ||= "X-Signature"
  options[:digest] ||= "SHA256"
end

#digestObject



18
19
20
# File 'lib/train-rest/auth_handler/hmac-signature.rb', line 18

def digest
  options[:digest]
end

#headerObject



22
23
24
# File 'lib/train-rest/auth_handler/hmac-signature.rb', line 22

def header
  options[:header]
end

#hmac_secretObject



14
15
16
# File 'lib/train-rest/auth_handler/hmac-signature.rb', line 14

def hmac_secret
  options[:hmac_secret]
end

#process(payload: "", headers: {}, url: "", method: nil) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/train-rest/auth_handler/hmac-signature.rb', line 30

def process(payload: "", headers: {}, url: "", method: nil)
  {
    headers: {
      header => OpenSSL::HMAC.hexdigest(digest, hmac_secret, payload)
    }
  }
end

#signature_based?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/train-rest/auth_handler/hmac-signature.rb', line 26

def signature_based?
  true
end