<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>JSDoc: Index</title>

    <script src="scripts/prettify/prettify.js"> </script>
    <script src="scripts/prettify/lang-css.js"> </script>
    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
    <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>

<body>

<div id="main">

    <h1 class="page-title">Index</h1>

    



    


    <h3>url-signer 0.1.2</h3>










    




    <section>
        <article><h1>url-signer</h1><p>Tiny library for signing and validating URLs. Also exposes an Express middleware which is optional to use.</p>
<p>Originally developed for <a href="http://quixel.se">Quixel</a>.</p>
<p>Inspired from <a href="https://www.npmjs.org/package/sign-url">sign-url</a> and <a href="https://www.npmjs.org/package/signed">signed</a> both of which didn't really float the boat.</p>
<h2>Usage</h2><h3>Initializing the singleton</h3><pre class="prettyprint source lang-javascript"><code>var signer = require('url-signer');

signer.init({
  privateKey: &quot;mySuperSecurePrivateKey&quot;, // required
  algorithm: &quot;sha256&quot;, // optional
  digest: &quot;base64&quot;, // optional
  ttl: 3600 // optional
});</code></pre><h3>Signing a URL</h3><pre class="prettyprint source lang-javascript"><code>var signedUrl = signer.getSignedUrl(&quot;http://site.com?id=50&accessToken=ae75ofjb7402&quot;);</code></pre><h3>Validating a URL</h3><pre class="prettyprint source lang-javascript"><code>var valid = signer.verifySignedUrl(signedUrl);
if (valid === true) {
  // all good; serve the secure payload
} else if (valid === 'expired') {
  // the signed url was valid but has been expired
} else{
  // the signed url is invalid  
}</code></pre><h3>Using the Express middleware</h3><pre class="prettyprint source lang-javascript"><code>// Using the default behavior of `signer.verifier()`
// Sends 403 if invalid
// Sends 410 if expired
app.get(&quot;/endpoint&quot;, signer.verifier(), function(req,res) {
  // all good!
  // res.sendStatus(200);
});

// Using the custom callbacks with `signer.verifier()`
app.get(&quot;/endpoint&quot;, signer.verifier({
  invalid: function(req, res) {
    // req.sendStatus(403);
  },
  expired: function(req, res) {
    // req.sendStatus(410);
  }  
}), function(req,res) {
  // all good!
  // res.sendStatus(200);
});</code></pre><h2>History</h2><h3>v0.1.2</h3><p>Cleaned up JSDoc comments</p>
<h3>v0.1.1</h3><p>Added some notes in README.md</p>
<h3>v0.1.0</h3><p>Initial release</p>
<h2>License</h2><p>The MIT License (MIT)</p>
<p>Copyright (c) 2014 Kamil Waheed</p>
<p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the &quot;Software&quot;), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:</p>
<p>The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.</p>
<p>THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</p></article>
    </section>






</div>

<nav>
    <h2><a href="index.html">Index</a></h2><h3>Modules</h3><ul><li><a href="module-signer.html">signer</a></li></ul>
</nav>

<br clear="both">

<footer>
    Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha10</a> on Sun Nov 23 2014 20:33:42 GMT+0500 (PKT)
</footer>

<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>