You are viewing documentation for version 2 of the AWS SDK for Ruby. Version 3 documentation can be found here.

Class: Aws::CloudFront::CookieSigner

Inherits:
Object
  • Object
show all
Includes:
Signer
Defined in:
aws-sdk-core/lib/aws-sdk-core/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
# File 'aws-sdk-core/lib/aws-sdk-core/cloudfront/cookie_signer.rb', line 27

def signed_cookie(url, params = {})
  scheme, uri = scheme_and_uri(url)
  signed_content = signature(
    resource: resource(scheme, uri),
    expires: time(params[:expires]),
    policy: params[:policy]
  )

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