Class: UrlAuthenticator::Signer

Inherits:
Object
  • Object
show all
Defined in:
lib/url_authenticator.rb

Instance Method Summary collapse

Constructor Details

#initialize(secret, expires = nil) ⇒ Signer

Returns a new instance of Signer.



43
44
45
46
# File 'lib/url_authenticator.rb', line 43

def initialize(secret, expires = nil)
  @secret = secret
  @expires = (expires || Time.now + 20 * 60).utc.to_i
end

Instance Method Details

#append_param(url, name, value) ⇒ Object



54
55
56
57
58
# File 'lib/url_authenticator.rb', line 54

def append_param(url, name, value)
  parameter = [name, value].join('=')
  separator = url.include?('?') ? '&' : '?'
  [url, parameter].join(separator)
end

#sign(url) ⇒ Object



48
49
50
51
52
# File 'lib/url_authenticator.rb', line 48

def sign(url)
  url = append_param(url, "expires", @expires)
  signature = OpenSSL::HMAC.hexdigest("md5", @secret, url)
  append_param(url, "signature", signature)
end