{"_id":"@a1motion/aws-cloudfront-sign","_rev":"1-ea55d751db86485eeb4729259b5e144c","name":"@a1motion/aws-cloudfront-sign","dist-tags":{"latest":"2.3.0"},"versions":{"2.3.0":{"name":"@a1motion/aws-cloudfront-sign","version":"2.3.0","description":"Utility module for signing AWS CloudFront URLs","author":{"name":"Jason Sims","email":"sims.jrobert@gmail.com"},"contributors":[{"name":"Matt Palmerlee"}],"main":"./lib/cloudfrontUtil.js","scripts":{"test":"./node_modules/.bin/mocha"},"repository":{"type":"git","url":"https://github.com/a1motion/aws-cloudfront-sign.git"},"keywords":["aws","CloudFront","signed URL"],"license":"MIT","bugs":{"url":"https://github.com/a1motion/aws-cloudfront-sign/issues"},"tonicExampleFilename":"./examples/signedURL.js","devDependencies":{"chai":"^2.2.0","lodash":"^4.17.15","mocha":"^2.2.1","moment":"^2.9.0","sinon":"^1.14.1"},"licenseText":"The MIT License (MIT)\n\nCopyright (c) 2014 \n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_id":"@a1motion/aws-cloudfront-sign@2.3.0","dist":{"shasum":"b8d8325f2a18815117c860bb1c25e5016b9e7e35","integrity":"sha512-rl2ZGB3mGlhX4dTeaRQW8PfU57wdxLyo0np3x8ucwYEccEBE3WnAykzdTsKJF77orIRIr+ay9HqyiyBt6ptayg==","tarball":"https://registry.npmjs.org/@a1motion/aws-cloudfront-sign/-/aws-cloudfront-sign-2.3.0.tgz","fileCount":20,"unpackedSize":34643,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdojxcCRA9TVsSAnZWagAAo28P/jrzN3HWte1L1/sHwcP5\nFCdcgtO+yuLa970BXwiimTyu2+n0nidG90eslavxuIg1Xte9BDvqlDq756pm\nY2OCfQ11uxcXbfofmiv7/0Qry+TopG6VuPShnIT1giy5Mpy+/YVei6LXYXXh\n9Abr7REoC0hvrCVRMouGI9B9oTvbLTgOHNp8pLRPJLbkfkI0wUk61G6m+k4Q\nFDK2w/OxPZmyfPt8pbDgaTlSh19FqfyhsLimeEpM068e30eG9XSbPIWvD94f\nTFZgCoUINTdQz7VbJkw/1Z8cgsyhE3jhGLGw4ebXvEU9cVje7E24TW5FA885\nR0S52PPG8s5KaYivr5bWLYl/+ix2MCrujdMEnU/PFyA9pzt8aGD8QjGixGcF\nJB/jt47tQsEQdR+TENvNbo1oEx3bjTWiovBatGYQljv4w5U+F5RFf18ldRle\nMn7zpqDzY3QxRaLEODP2ESTTj09XctPUnA7c5oiNwz23bs+QuPq8LUI9ZdtM\nGGUlwtHCT1g3T0pOvrSMwM3VVgRU1DtwMDMc1x8ILpigB3Y9Plfv/2/Ff9+9\nqM+CM7ZHPLG6cSJ9qHdebBTsDmOb/oppm3aq0v71PPF6Zy1aRcIUcL+6Ad4H\n1S+eq2lAI5W1zYT6WC6wkR18wiBfZwJJb2s5reCSkW1V9EPpYA82FJo3uaNq\nIQv6\r\n=VPS+\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIANldlYd6bpuU3RGhL7CgyIBFgKYS1Q4CValgDOsEWWzAiEAiEEc/61/+C77wVx/GvFeLATu994PsxyrgnY9MNc8M/8="}]},"maintainers":[{"name":"dotconnor","email":"connor@dotconnor.com"}],"_npmUser":{"name":"dotconnor","email":"connor@dotconnor.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/aws-cloudfront-sign_2.3.0_1570913371621_0.9521935545619262"},"_hasShrinkwrap":false}},"time":{"created":"2019-10-12T20:49:31.534Z","2.3.0":"2019-10-12T20:49:31.760Z","modified":"2022-04-04T10:52:51.275Z"},"maintainers":[{"name":"dotconnor","email":"connor@dotconnor.com"}],"description":"Utility module for signing AWS CloudFront URLs","keywords":["aws","CloudFront","signed URL"],"repository":{"type":"git","url":"https://github.com/a1motion/aws-cloudfront-sign.git"},"contributors":[{"name":"Matt Palmerlee"}],"author":{"name":"Jason Sims","email":"sims.jrobert@gmail.com"},"bugs":{"url":"https://github.com/a1motion/aws-cloudfront-sign/issues"},"license":"MIT","readme":"AWS CloudFront URL Signature Utility  \n===================\n[![Build Status](https://travis-ci.org/jasonsims/aws-cloudfront-sign.svg?branch=master)](https://travis-ci.org/jasonsims/aws-cloudfront-sign)\n[![npm version](https://badge.fury.io/js/aws-cloudfront-sign.svg)](http://badge.fury.io/js/aws-cloudfront-sign)\n\nGenerating signed URLs for CloudFront links is a little more tricky than for S3. It's because signature generation for S3 URLs is handled a bit differently than CloudFront URLs and this functionality is not currently supported by the [aws-sdk](https://github.com/aws/aws-sdk-js) library for JavaScript. In case you also need to do this, I've created this simple utility to make things easier.\n\n## Usage\n### Requirements\n* Node.js >=0.10.0\n* Active CloudFront distribution with origin configured\n\n### Configuring CloudFront\n1. Create a CloudFront distribution\n2. Configure your origin with the following settings:\n\n   **Origin Domain Name:** {your-s3-bucket}  \n   **Restrict Bucket Access:** Yes  \n   **Grant Read Permissions on Bucket:** Yes, Update Bucket Policy  \n3. Create CloudFront Key Pair. [more info][cf_keypair_docs]\n\n### Installing\n```sh\nnpm install aws-cloudfront-sign\n```\n\n### Upgrading from 1.x to 2.x\n* `expireTime` now takes it's value as milliseconds, Date, or\n [moment][moment_docs] instead of seconds.\n\n### API\n#### getSignedUrl(url, options)\n* `@param {String} url` - Cloudfront URL to sign\n* `@param {Object} options` - URL signature [options](#options)\n* `@return {String} signedUrl` - Signed CloudFrontUrl\n\n#### getSignedRTMPUrl(domainName, s3key, options)\n* `@param {String} domainName` - Domain name of your Cloudfront distribution\n* `@param {String} s3key` - Path to s3 object\n* `@param {Object} options` - URL signature [options](#options)\n* `@return {Object} url.rtmpServerPath` - RTMP formatted server path\n* `@return {Object} url.rtmpStreamName` - Signed RTMP formatted stream name\n\n#### getSignedCookies(url, options)\n* `@param {String} url` - Cloudfront URL to sign\n* `@param {Object} options` - URL signature [options](#options)\n* `@return {Object} cookies` - Signed AWS cookies\n\n### Options\n* `expireTime` (**Optional** - Default: 1800 sec == 30 min) - The time when the URL should expire. Accepted values are\n   * number - Time in milliseconds (`new Date().getTime() + 1800000`)\n   * moment - Valid [momentjs][moment_docs] object (`moment().add(1, 'day')`)\n   * Date - Javascript Date object (`new Date(2016, 0, 1)`)\n* `ipRange` (**Optional**) - IP address range allowed to make GET requests\n  for your signed URL. This value must be given in standard IPv4 CIDR format\n  (for example, 10.52.176.0/24).\n* `keypairId` - The access key ID from your Cloudfront keypair\n* `privateKeyString` || `privateKeyPath` - The private key from your Cloudfront\n   keypair. It can be provided as either a string or a path to the .pem file.\n  **Note:** When providing the private key as a string, ensure that the newline\n  character is also included.\n\n  ```js\n  var privateKeyString =\n    '-----BEGIN RSA PRIVATE KEY-----\\n'\n    'MIIJKAIBAAKCAgEAwGPMqEvxPYQIffDimM9t3A7Z4aBFAUvLiITzmHRc4UPwryJp\\n'\n    'EVi3C0sQQKBHlq2IOwrmqNiAk31/uh4FnrRR1mtQm4x4IID58cFAhKkKI/09+j1h\\n'\n    'tuf/gLRcOgAXH9o3J5zWjs/y8eWTKtdWv6hWRxuuVwugciNckxwZVV0KewO02wJz\\n'\n    'jBfDw9B5ghxKP95t7/B2AgRUMj+r47zErFwo3OKW0egDUpV+eoNSBylXPXXYKvsL\\n'\n    'AlznRi9xNafFGy9tmh70pwlGG5mVHswD/96eUSuLOZ2srcNvd1UVmjtHL7P9/z4B\\n'\n    'KdODlpb5Vx+54+Fa19vpgXEtHgfAgGW9DjlZMtl4wYTqyGAoa+SLuehjAQsxT8M1\\n'\n    'BXqfMJwE7D9XHjxkqCvd93UGgP+Yxe6H+HczJeA05dFLzC87qdM45R5c74k=\\n'\n    '-----END RSA PRIVATE KEY-----'\n  ```\n  Also, here are some examples if prefer to store your private key as a string\n  but within an environment variable.\n  ```sh\n  # Local env example\n  CF_PRIVATE_KEY=\"$(cat your-private-key.pem)\"\n\n  # Heroku env\n  heroku config:set CF_PRIVATE_KEY=\"$(cat your-private-key.pem)\"  \n  ```\n\n## Examples\n### Creating a signed URL\nBy default the URL will expire after half an hour.\n```js\nvar cf = require('aws-cloudfront-sign')\nvar options = {keypairId: 'APKAJM2FEVTI7BNPCY4A', privateKeyPath: '/foo/bar'}\nvar signedUrl = cf.getSignedUrl('http://xxxxxxx.cloudfront.net/path/to/s3/object', options);\nconsole.log('Signed URL: ' + signedUrl);\n```\n\n### Creating a signed RTMP URL\n```js\nvar cf = require('aws-cloudfront-sign')\nvar options = {keypairId: 'APKAJM2FEVTI7BNPCY4A', privateKeyPath: '/foo/bar'}\nvar signedRTMPUrlObj = cf.getSignedRTMPUrl('xxxxxxx.cloudfront.net', '/path/to/s3/object', options);\nconsole.log('RTMP Server Path: ' + signedRTMPUrlObj.rtmpServerPath);\nconsole.log('Signed Stream Name: ' + signedRTMPUrlObj.rtmpStreamName);\n```\n\n### Creating signed cookies\n```js\nvar cf = require('aws-cloudfront-sign')\nvar options = {keypairId: 'APKAJM2FEVTI7BNPCY4A', privateKeyPath: '/foo/bar'}\nvar signedCookies = cf.getSignedCookies('http://xxxxxxx.cloudfront.net/*', options);\n\n// You can now set cookies in your response header. For example:\nfor(var cookieId in signedCookies) {\n res.cookie(cookieId, signedCookies[cookieId]);\n}\n```\n\n[moment_docs]: http://momentjs.com/docs\n[cf_keypair_docs]: http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-trusted-signers.html#private-content-creating-cloudfront-key-pairs\n","readmeFilename":"README.md"}