lib/cloudfront/signer.js
function (options, cb) {
        try {
            var resource = getResource(options.url);
        } catch (err) {
            return handleError(err, cb);
        }

        var parsedUrl = url.parse(options.url, true),
            signatureHash = Object.prototype.hasOwnProperty.call(options, 'policy')
                ? signWithCustomPolicy(options.policy, this.keyPairId, this.privateKey)
                : signWithCannedPolicy(resource, options.expires, this.keyPairId, this.privateKey);

        parsedUrl.search = null;
        for (var key in signatureHash) {
            if (Object.prototype.hasOwnProperty.call(signatureHash, key)) {
                parsedUrl.query[key] = signatureHash[key];
            }
        }

        try {
            var signedUrl = determineScheme(options.url) === 'rtmp'
                    ? getRtmpUrl(url.format(parsedUrl))
                    : url.format(parsedUrl);
        } catch (err) {
            return handleError(err, cb);
        }

        return handleSuccess(signedUrl, cb);
    }
function (options, cb) {
        try {
            var resource = getResource(options.url);
        } catch (err) {
            return handleError(err, cb);
        }

        var parsedUrl = url.parse(options.url, true),
            signatureHash = Object.prototype.hasOwnProperty.call(options, 'policy')
                ? signWithCustomPolicy(options.policy, this.keyPairId, this.privateKey)
                : signWithCannedPolicy(resource, options.expires, this.keyPairId, this.privateKey);

        parsedUrl.search = null;
        for (var key in signatureHash) {
            if (Object.prototype.hasOwnProperty.call(signatureHash, key)) {
                parsedUrl.query[key] = signatureHash[key];
            }
        }

        try {
            var signedUrl = determineScheme(options.url) === 'rtmp'
                    ? getRtmpUrl(url.format(parsedUrl))
                    : url.format(parsedUrl);
        } catch (err) {
            return handleError(err, cb);
        }

        return handleSuccess(signedUrl, cb);
    }
function ( options , cb ) { try { var resource = getResource ( options . url ) ; } catch ( err ) { return handleError ( err , cb ) ; } var parsedUrl = url . parse ( options . url , true ) , signatureHash = Object . prototype . hasOwnProperty . call ( options , 'policy' ) ? signWithCustomPolicy ( options . policy , this . keyPairId , this . privateKey ) : signWithCannedPolicy ( resource , options . expires , this . keyPairId , this . privateKey ) ; parsedUrl . search = null ; for ( var key in signatureHash ) { if ( Object . prototype . hasOwnProperty . call ( signatureHash , key ) ) { parsedUrl . query [ key ] = signatureHash [ key ] ; } } try { var signedUrl = determineScheme ( options . url ) === 'rtmp' ? getRtmpUrl ( url . format ( parsedUrl ) ) : url . format ( parsedUrl ) ; } catch ( err ) { return handleError ( err , cb ) ; } return handleSuccess ( signedUrl , cb ) ; }
Create a signed Amazon CloudFront URL.

Keep in mind that URLs meant for use in media/flash players may have
different requirements for URL formats (e.g. some require that the
extension be removed, some require the file name to be prefixed
- mp4:<path>, some require you to add "/cfx/st" into your URL).

@param options [Object]          The options to create a signed URL.
@option options url [String]     The URL to which the signature will grant
access. Any query params included with
the URL should be encoded. Required.
@option options expires [Number] A Unix UTC timestamp indicating when the
signature should expire. Required unless you
pass in a full policy.
@option options policy [String]  A CloudFront JSON policy. Required unless
you pass in a url and an expiry time.

@param cb [Function] if a callback is provided, this function will
pass the URL as the second parameter (after the error parameter) to
the callback function.

@return [String] if called synchronously (with no callback), returns the
signed URL.
@return [null] nothing is returned if a callback is provided.
Create a signed Amazon CloudFront URL .