Download the PHP package maize-tech/laravel-cloudfront-cookies without Composer

On this page you can find all versions of the php package maize-tech/laravel-cloudfront-cookies. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-cloudfront-cookies

Laravel CloudFront Cookies

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A Laravel package to easily manage AWS CloudFront signed cookies for authenticated users. This package automatically generates and manages CloudFront signed cookies, allowing you to restrict access to your CloudFront distributions based on user authentication status. Cookies are automatically set for authenticated users and cleared on logout.

Installation

You can install the package via composer:

You can install and configure the package with:

This is the contents of the published config file:

AWS CloudFront Setup

Before using this package, you need to configure AWS CloudFront with signed cookies. This guide assumes you already have an S3 bucket with your assets and a domain name hosted on the internet.

1. Generate Public and Private Keys

Create a new RSA private key:

Extract the public key:

Important: Store the cloudfront-private.key file in your Laravel application's storage directory. This is the default location the package looks for the private key.

2. Create a CloudFront Key Group

  1. Go to the AWS CloudFront console
  2. Navigate to Key management > Public keys
  3. Click Create public key
  4. Give it a name (e.g., "My App Public Key")
  5. Paste the content of cloudfront-public.key
  6. Save and note down the Key ID (you'll need this for CLOUDFRONT_KEY_PAIR_ID)
  7. Navigate to Key groups and create a new key group
  8. Add the public key you just created to this key group

3. Create a CloudFront Distribution

Important: Your CloudFront distribution must use the same root domain as your application. For example, if your application is at example.com, your CloudFront domain should be something like assets.example.com or cdn.example.com. This is necessary because cookies can only be set for domains you own.

  1. Go to the CloudFront console and click Create distribution
  2. Under Origin domain, select your S3 bucket with the assets
  3. Under Default cache behavior:
    • Set Restrict viewer access to Yes
    • Select the key group you created earlier
  4. Under Settings:
    • Add your custom SSL certificate (e.g., *.example.com)
    • Under Alternate domain name (CNAME), add your CloudFront domain (e.g., cdn.example.com)
  5. Create the distribution (this may take 10-15 minutes to deploy)
  6. Note down the Distribution domain name (e.g., d1234abcd.cloudfront.net) and the full CloudFront URL (e.g., https://d1234abcd.cloudfront.net/*)

4. Configure DNS

Access your domain name's provider DNS panel and create a CNAME record pointing to your ClouFront distribution, i.e.:

If you are using AWS Route 53, follow these steps:

  1. Go to Route 53 and select your hosted zone
  2. Click Create record
  3. Set the record name to match your CloudFront CNAME (e.g., cdn)
  4. Enable the Alias toggle
  5. Select CloudFront distribution as the alias target
  6. Select your distribution from the dropdown
  7. Create the record

If you don't see your distribution in the dropdown, you can use a CNAME record type instead and use the CloudFront domain name as the value.

5. Update S3 Bucket CORS Policy

  1. Go to your S3 bucket
  2. Navigate to the Permissions tab
  3. Scroll to the Cross-origin resource sharing (CORS) section
  4. Update the policy (replace example.com and cdn.example.com with your domains):

Make sure to protect your bucket by seleting "Block all public access" under "Permissions".

Usage

Add the SignCloudfrontCookies middleware to your routes or route groups:

Note for Laravel versions prior to 11: You need to manually exclude CloudFront cookies from encryption. Add the following to your app/Http/Middleware/EncryptCookies.php:

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-cloudfront-cookies with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
aws/aws-sdk-php Version ^3.337
illuminate/contracts Version ^10.0||^11.0||^12.0
spatie/laravel-package-tools Version ^1.16
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package maize-tech/laravel-cloudfront-cookies contains the following files

Loading the files please wait ...