Class: Aws::CloudFront::CookieSigner

Inherits:
Object
  • Object
show all
Includes:
Signer
Defined in:
lib/aws-sdk-cloudfront/cookie_signer.rb

Overview

Allows you to create signed cookie for Amazon CloudFront resources

signer = Aws::CloudFront::CookieSigner.new(
  key_pair_id: "cf-keypair-id",
  private_key_path: "./cf_private_key.pem"
)
cookies = signer.signed_cookie(url,
  policy: policy.to_json
)

Instance Method Summary collapse

Methods included from Signer

#initialize

Instance Method Details

create a set of signed Amazon CloudFront cookie parameters

Parameters:

  • url (String)
  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :expires (Time, DateTime, Date, String, Integer<timestamp>)
  • :policy (String<JSON>)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/aws-sdk-cloudfront/cookie_signer.rb', line 27

def signed_cookie(url, params = {})
  content = {}.tap do |c|
    if params[:policy]
      c[:policy] = params[:policy]
    elsif url && params[:expires]
      scheme, uri = scheme_and_uri(url)
      c[:resource] = resource(scheme, uri)
      c[:expires] = time(params[:expires])
    end
  end

  cookie_parameters = {}
  signature(content).each { |k, v|
    cookie_parameters["CloudFront-#{k}"] = v.to_s.gsub("\n", '')
  }
  cookie_parameters
end