Last active
October 11, 2016 08:47
-
-
Save waynehoover/6577723 to your computer and use it in GitHub Desktop.
nginx rails secure_link example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Order < ActiveRecord::Base | |
DOWNLOAD_EXPIRY = 10.days | |
def secure_download_link | |
time = (Time.now + DOWNLOAD_EXPIRY).to_i | |
hmac = Digest::MD5.base64digest("#{time}#{self.file_path} #{ENV['DOWNLOAD_SECRET']}").tr("+/","-_").gsub("==",'') | |
"http://files.domain.com/downloads/#{file_path}?md5=#{hmac}&expires=#{time}" | |
end | |
... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
.gsub("==",'')
could be replaced with.tr('=', '')