Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cloudfront-signed-cookies

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cloudfront-signed-cookies

A Python package for controlling access to content sitting behind a CloudFront distribution using signed cookies.

  • 1.2
  • Source
  • PyPI
  • Socket score

Maintainers
1

cloudfront-signed-cookies

PyPI - Version PyPI - Python Version Hatch project Code style: black


IF YOU'RE INTERESTED, go checkout my Medium blog post for a deeper dive on what this package is doing and some usage examples.

Table of Contents

Installation

pip install cloudfront-signed-cookies

Usage

from cloudfront_signed_cookies.signer import Signer
import os

def main():
    """
    Method #1
    Allow the signer to read your key from a file
    """
    signer: Signer = Signer(
        cloudfront_key_id="K36X4X2EO997HM",
        private_key="./certs/private_key.pem",
    )

    """
    Method #2
    Alternatively you can pass the raw contents of the key in from
    something such as an environment variable, for container (Docker)
    based usage
    """
    signer: Signer = Signer(
        cloudfront_key_id="K36X4X2EO997HM",
        private_key=os.environ.get("PRIVATE_KEY")
    )

    cookies: dict = signer.generate_cookies(
        Policy={
            "Statement": [
                {
                    "Resource": "https://domain.com/somefile.txt",
                    "Condition": {
                        "DateLessThan": {
                            "AWS:EpochTime": 1000
                        }
                    },
                }
            ]
        },
        SecondsBeforeExpires=360,
    )
    print(cookies)

main()
"""
{'CloudFront-Policy': 'eyJTdGF0ZW1lbnQiOlt7IlJlc291cmNlIjoic29tZV91cmwiLCJDb25kaXRpb24iOnsiRGF0ZUxlc3NUaGFuIjp7IkFXUzpFcG9jaFRpbWUiOjEwMDB9fX1dfQ__', 'CloudFront-Signature': 'EZHxOEAhaKB3e-XUAGI5xJdDQaWKuW-h6m8c4UYcFBkaA3Fh4~DygZUcYCj-S-qtUdrl46i8vp4RuvtDz4sL9GEVGGDniZc8iDVDqHmfllMFK-90Ge-C9lQ-umsqm-IQzaFVDS3WMbi5iAsRDpdUGfAk43ergTMvjhd~xxpVCCHZxW8uBt11kAjEoqdbMm6eVC32F-QB2HJndN9mm4d~dizvW~XjVt69fA0YjY7-TiIVKAO5ajnDaBl17AsLolLfLYl6NGBJjadLjueMCWM2DP5lXYce8RF2qW02wg8bNmth3ykPoVHFT-tgIgetOcDFDCFSnTkXXhUy3mu2wPzdKQ__', 'CloudFront-Key-Pair-Id': K36X4X2EO997HM'}
"""

License

cloudfront-signed-cookies is distributed under the terms of the MIT license.

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc