UNPKG

feathers-authentication-jwt

Version:

JWT authentication strategy for feathers-authentication using Passport

189 lines (188 loc) 5.59 kB
<!doctype html> <html lang="en"> <head> <title>Code coverage report for verifier.js</title> <meta charset="utf-8" /> <link rel="stylesheet" href="prettify.css" /> <link rel="stylesheet" href="base.css" /> <meta name="viewport" content="width=device-width, initial-scale=1"> <style type='text/css'> .coverage-summary .sorter { background-image: url(sort-arrow-sprite.png); } </style> </head> <body> <div class='wrapper'> <div class='pad1'> <h1> <a href="index.html">All files</a> verifier.js </h1> <div class='clearfix'> <div class='fl pad1y space-right2'> <span class="strong">100% </span> <span class="quiet">Statements</span> <span class='fraction'>22/22</span> </div> <div class='fl pad1y space-right2'> <span class="strong">90% </span> <span class="quiet">Branches</span> <span class='fraction'>9/10</span> </div> <div class='fl pad1y space-right2'> <span class="strong">100% </span> <span class="quiet">Functions</span> <span class='fraction'>3/3</span> </div> <div class='fl pad1y space-right2'> <span class="strong">100% </span> <span class="quiet">Lines</span> <span class='fraction'>21/21</span> </div> </div> </div> <div class='status-line high'></div> <pre><table class="coverage"> <tr><td class="line-count quiet">1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42</td><td class="line-coverage quiet"><span class="cline-any cline-yes">1x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">36x</span> <span class="cline-any cline-yes">36x</span> <span class="cline-any cline-yes">36x</span> <span class="cline-any cline-yes">36x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">36x</span> <span class="cline-any cline-yes">1x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">35x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">8x</span> <span class="cline-any cline-yes">8x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">8x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">8x</span> <span class="cline-any cline-yes">2x</span> <span class="cline-any cline-yes">2x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">6x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">6x</span> <span class="cline-any cline-yes">4x</span> <span class="cline-any cline-yes">4x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">3x</span> <span class="cline-any cline-yes">3x</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">import Debug from 'debug'; &nbsp; const debug = Debug('feathers-authentication-jwt:verify'); &nbsp; class JWTVerifier { constructor (app, options = <span class="branch-1 cbranch-no" title="branch not covered" >{}) {</span> this.app = app; this.options = options; this.service = typeof options.service === 'string' ? app.service(options.service) : options.service; &nbsp; if (!this.service) { throw new Error(`options.service does not exist.\n\tMake sure you are passing a valid service path or service instance and it is initialized before feathers-authentication-jwt.`); } &nbsp; this.verify = this.verify.bind(this); } &nbsp; verify (req, payload, done) { debug('Received JWT payload', payload); &nbsp; const id = payload[`${this.options.entity}Id`]; &nbsp; if (id === undefined) { debug(`JWT payload does not contain ${this.options.entity}Id`); return done(null, {}, payload); } &nbsp; debug(`Looking up ${this.options.entity} by id`, id); &nbsp; this.service.get(id).then(entity =&gt; { const newPayload = { [`${this.options.entity}Id`]: id }; return done(null, entity, newPayload); }) .catch(error =&gt; { debug(`Error populating ${this.options.entity} with id ${id}`, error); return done(null, {}, payload); }); } } &nbsp; export default JWTVerifier; &nbsp;</pre></td></tr> </table></pre> <div class='push'></div><!-- for sticky footer --> </div><!-- /wrapper --> <div class='footer quiet pad2 space-top1 center small'> Code coverage generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Wed Apr 12 2017 20:47:28 GMT-0700 (PDT) </div> </div> <script src="prettify.js"></script> <script> window.onload = function () { if (typeof prettyPrint === 'function') { prettyPrint(); } }; </script> <script src="sorter.js"></script> </body> </html>