Class: UrlAuthenticator::Signer
- Inherits:
-
Object
- Object
- UrlAuthenticator::Signer
- Defined in:
- lib/url_authenticator.rb
Instance Method Summary collapse
- #append_param(url, name, value) ⇒ Object
-
#initialize(secret, expires = nil) ⇒ Signer
constructor
A new instance of Signer.
- #sign(url) ⇒ Object
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 |