· 7 years ago · Sep 10, 2018, 03:40 AM
1class UploadsController < ApplicationController
2 before_action :require_login
3
4 def auth
5 date_stamp = Date.strptime(params[:datetime], "%Y%m%dT%H%M%SZ").strftime("%Y%m%d")
6 secret_key = "AWS_SECRET_KEY"
7 aws_region = "us-east-1" # << set to your region
8
9 date_key = OpenSSL::HMAC.digest("sha256", "AWS4" + secret_key, date_stamp)
10 region_key = OpenSSL::HMAC.digest("sha256", date_key, aws_region)
11 service_key = OpenSSL::HMAC.digest("sha256", region_key, "s3")
12 signing_key = OpenSSL::HMAC.digest("sha256", service_key, "aws4_request")
13
14 render plain: OpenSSL::HMAC.hexdigest("sha256", signing_key, params[:to_sign]).gsub("\n", "")
15 end
16
17end