Sha256: 73384a161e627d01920694d61d31301f2600a0b554caaf7b5a48a5e30272e97d

Contents?: true

Size: 1.27 KB

Versions: 20

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

require 'base64'
require 'uri'
require 'time'
require 'openssl'

module Aws
  module CloudFront

    # Allows you to create signed cookie for Amazon CloudFront resources
    #
    #     signer = Aws::CloudFront::CookieSigner.new(
    #       key_pair_id: "cf-keypair-id",
    #       private_key_path: "./unit_test_dummy_key"
    #     )
    #     cookies = signer.signed_cookie(url,
    #       policy: policy.to_json
    #     )
    #
    class CookieSigner
      include Signer

      # create a set of signed Amazon CloudFront cookie parameters
      # @param [String] url
      # @option params [Time, DateTime, Date, String, Integer<timestamp>] :expires
      # @option params [String<JSON>] :policy
      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.delete("\n")
        }
        cookie_parameters
      end

    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
aws-sdk-cloudfront-1.107.0 lib/aws-sdk-cloudfront/cookie_signer.rb
aws-sdk-cloudfront-1.106.0 lib/aws-sdk-cloudfront/cookie_signer.rb
aws-sdk-cloudfront-1.105.0 lib/aws-sdk-cloudfront/cookie_signer.rb
aws-sdk-cloudfront-1.104.0 lib/aws-sdk-cloudfront/cookie_signer.rb
aws-sdk-cloudfront-1.103.0 lib/aws-sdk-cloudfront/cookie_signer.rb
aws-sdk-cloudfront-1.102.0 lib/aws-sdk-cloudfront/cookie_signer.rb
aws-sdk-cloudfront-1.101.0 lib/aws-sdk-cloudfront/cookie_signer.rb
aws-sdk-cloudfront-1.100.0 lib/aws-sdk-cloudfront/cookie_signer.rb
aws-sdk-cloudfront-1.99.0 lib/aws-sdk-cloudfront/cookie_signer.rb
aws-sdk-cloudfront-1.98.0 lib/aws-sdk-cloudfront/cookie_signer.rb
aws-sdk-cloudfront-1.97.0 lib/aws-sdk-cloudfront/cookie_signer.rb
aws-sdk-cloudfront-1.96.0 lib/aws-sdk-cloudfront/cookie_signer.rb
aws-sdk-cloudfront-1.95.0 lib/aws-sdk-cloudfront/cookie_signer.rb
aws-sdk-cloudfront-1.94.0 lib/aws-sdk-cloudfront/cookie_signer.rb
aws-sdk-cloudfront-1.93.0 lib/aws-sdk-cloudfront/cookie_signer.rb
aws-sdk-cloudfront-1.92.0 lib/aws-sdk-cloudfront/cookie_signer.rb
aws-sdk-cloudfront-1.89.0 lib/aws-sdk-cloudfront/cookie_signer.rb
aws-sdk-cloudfront-1.88.0 lib/aws-sdk-cloudfront/cookie_signer.rb
aws-sdk-cloudfront-1.87.0 lib/aws-sdk-cloudfront/cookie_signer.rb
aws-sdk-cloudfront-1.86.1 lib/aws-sdk-cloudfront/cookie_signer.rb