Code Monkey home page Code Monkey logo

cloudfront-private-url-creator's Introduction

cloudfront-private-url-creator

Creates and signs private Cloudfront Urls (http:, https:, rtmp:, rtmpt:, rtmpe:, and rtmpte:)

travis npm downloads standard

Installation:

npm i cloudfront-private-url-creator

Note:

If you are using Node 0.10 - 0.12, please use version 1.1.0.

Usage:

'use strict'
const fs = require('fs')
const cf = require('cloudfront-private-url-creator')

const urlToSign = 'https://somedistro.cloudfront.net/somefolder/someFile'
const keyPairId = 'yourKeyPaidId'
const privateKeyPath = './yourKey.pem'

// date when the private url will expire (1 hour from now in this case)
const dateLessThan = new Date()
dateLessThan.setHours(dateLessThan.getHours() + 1)

const privateKey = fs.readFileSync(privateKeyPath)

const config = {
  privateKey,
  keyPairId,
  dateLessThan
}
// sign the url and return it, or just get the signature
const signatureQueryString = cf.getSignatureQueryString(urlToSign, config)
// OR
const signedUrl = cf.signUrl(urlToSign, config)

Relevant AWS docs:

Creating a Signed URL Using a Canned Policy

Creating a Signed URL Using a Custom Policy

Contributors

Here's a list, thanks for your help!

cloudfront-private-url-creator's People

Contributors

dependabot[bot] avatar gcurtisct avatar greenkeeper[bot] avatar maxnachlinger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cloudfront-private-url-creator's Issues

An in-range update of tape is breaking the build 🚨

The devDependency tape was updated from 4.9.2 to 4.10.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

tape is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 60 commits.

  • 34b1832 v4.10.0
  • 6209882 Merge all orphaned tags: 'v1.1.2', 'v2.0.2', 'v2.1.1', 'v2.2.2', 'v2.3.3', 'v2.4.3', 'v2.5.1', 'v2.6.1', 'v2.7.3', 'v2.8.1', 'v2.9.1', 'v2.10.3', 'v2.11.1', 'v2.13.4', 'v2.14.0', 'v2.14.1', 'v3.6.1'
  • 82e7b26 [Deps] update glob
  • 9e3d25e [Dev Deps] update eslint, js-yaml
  • fd807f5 v1.1.2
  • eddbff5 v2.14.1
  • 6ce09d9 Minor test tweaks due to whitespace differences in v2 vs v4.
  • 71af8ba gitignore node_modules
  • 4c0d9e6 Merge pull request #268 from ljharb/throws_non_function_should_fail
  • d0a675f v3.6.1
  • d22b5fc Minor test tweaks due to output differences in v1 vs v4.
  • 8b3c1b7 Add missing concat-stream devDep
  • 3495543 gitignore node_modules
  • db81846 Merge pull request #268 from ljharb/throws_non_function_should_fail
  • 7ed6651 Minor test tweaks due to whitespace differences in v3 vs v4.

There are 60 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Playback Failed. Failed to play (stream: ID 1)

I'm trying to play back a video hosted on S3, through cloudfront, using a signed URL

I'm using pretty much the exact code from your example.

I send it: rtmp://xxxxxxxxxxxxx.cloudfront.net/cfx/st/vid_test001 and I get back

rtmp://xxxxxxxxxxxxx.cloudfront.net/cfx/st/vid_test001?Signature=SseYBRTNBTBEeQFA15o467er7EegaZwe6OM3w2AZap8Bla1WU~zXJxzUJqigyAECpbMEGHyPIEGmkFdLoU~gKgEoGUufy9TAGCkei-hjiVfMtcw2-iDVDKX~NyFScJc-fMrLD~67nWmkNAlUAZJKJV5WOqV~jgCMlQVgDbUsnLWQ0llST9qWvQp2dOqWVcvnQI1QfYzZOQxdaqZ8FY-gOzPmu8swGL95aeQQkz2VUkRTPI569ktA5rorVWmHyKbXT0jUJSBy1nEgNTDZIZSzEloTPH48RI6RpZ70qm0ahN~TrMzriEJpf4hDE2HR1DboQSxjS4JyYTr5Hdg__&Key-Pair-Id=APKAJSRQXYNPUENHF6HQ&Expires=1386356652

Which seems like an acceptable url.

However, when I try to play it back, I get Failed to play (stream ID:1) from the SMP player.

My permissions for Cloudfront are this:

Restrict Bucket Access : Yes
Grant Read Permissions on Bucket : No, I will Update Permissions
Restrict Viewer Access (Use Signed URLs) : Yes
Trusted Signers : Self
Distribution State: Enabled

The "Grant Read Permissions on Bucket" option might be causing problems, but I can't seem to change this to "Yes" instead of "No". If I change it, save, and come back and view the settings, it changes back to "no"

My bucket policy is

{
    "Version": "2008-10-17",
    "Id": "PolicyForCloudFrontPrivateContent",
    "Statement": [
        {
            "Sid": "1",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity EF5LIV7LW3XE4"
            },
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::ct.recorder/*"
        }
    ]
}

wild-card character

First of all, thank you very much indeed for providing this module.
This module works fine with specific resource.
I try to signing per user like hereinafter:

        var dateLessThan = new Date();
        dateLessThan.setHours(dateLessThan.getHours()+1);

        var urlToSign = 'https://mycf.cloudfront.net/privates/' + userid + '/*';

        if (cloudFrontPrivateKey) {
            var policy = {
                privateKey: cloudFrontPrivateKey,
                keyPairId: cloudFrontKeyPairID,
                dateLessThan: dateLessThan
            };
            var signedUrl = cf.signUrl(urlToSign, policy);
            var signed = signedUrl.replace(urlToSign + '?', '');

            res.json({
                authorization: 'success',
                signed: signed
            });
        }

And then, I make download url in front javascript.

       $('down').html('<a href="https://mycf.cloudfront.net/privates/' + userid + '/test/resource.obj?'+data.signed+'">download</a>');

It doesn't work. Could you give me any advices what is wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.