Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Generate auth token url for nonpublic files.

Public url generation moved to the Attachment#public_url method.
  • Loading branch information...
commit d96de83a0dd5897a557e58ba1d12dd445ac9956a 1 parent 4a7c311
Hristo Deshev authored
Showing with 27 additions and 5 deletions.
  1. +9 −0 lib/filer/attachment.rb
  2. +18 −5 lib/filer/config.rb
View
9 lib/filer/attachment.rb
@@ -71,6 +71,15 @@ def blank?
def url
if !blank?
+ token = Progstr::Filer.generate_file_auth_token(id)
+ "#{Progstr::Filer.url_prefix}files/data/#{Progstr::Filer.access_key}/#{id}?auth=#{token}"
+ else
+ ""
+ end
+ end
+
+ def public_url
+ if !blank?
"#{Progstr::Filer.url_prefix}files/data/#{Progstr::Filer.access_key}/#{id}"
else
""
View
23 lib/filer/config.rb
@@ -27,11 +27,17 @@ def session_timeout
end
def generate_auth_token
- expiration_seconds = (Time.now + session_timeout).to_i
- expiration_millis = expiration_seconds * 1000
- data = "#{access_key}-#{expiration_millis}-#{secret_key}"
- signature = Digest::SHA1.hexdigest(data)
- "#{access_key}-#{expiration_millis}-#{signature}"
+ expiration = expiration_time
+ to_sign = "#{access_key}-#{expiration}-#{secret_key}"
+ signature = Digest::SHA1.hexdigest(to_sign)
+ "#{access_key}-#{expiration}-#{signature}"
+ end
+
+ def generate_file_auth_token(file_id)
+ expiration = expiration_time
+ to_sign = "#{access_key}-#{file_id}-#{expiration}-#{secret_key}"
+ signature = Digest::SHA1.hexdigest(to_sign)
+ "#{access_key}-#{expiration}-#{signature}"
end
def url_prefix
@@ -42,6 +48,13 @@ def url_prefix
prefix + "/"
end
end
+
+ private
+ def expiration_time
+ seconds = (Time.now + session_timeout).to_i
+ millis = seconds * 1000
+ millis
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.