Gathering detailed insights and metrics for koa-eula
Approximately 800 new packages are uploaded to the npm registry every day. This number can vary, but it reflects the active and growing nature of the JavaScript development community.
Gathering detailed insights and metrics for koa-eula
Approximately 800 new packages are uploaded to the npm registry every day. This number can vary, but it reflects the active and growing nature of the JavaScript development community.
npm install koa-eula
67.8
Supply Chain
99.2
Quality
73.7
Maintenance
50
Vulnerability
98.6
License
9 Commits
2 Watching
1 Branches
1 Contributors
Updated on 07 Feb 2017
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
100%
2
Compared to previous day
Last week
150%
5
Compared to previous week
Last month
44.4%
13
Compared to previous month
Last year
5.8%
146
Compared to previous year
2
Koa middleware that validates JSON Web Tokens and sets ctx.state.eula
(by default) if a valid EULA token is provided.
This module lets you validate EULA on HTTP requests using JSON Web Tokens in your Koa (node.js) applications.
1npm install koa-eula
The JWT eula middleware validate EULA acceptation of callers using a JWT
token. If the token is valid, ctx.state.eula
(by default) will be set
with the JSON object decoded to be used by later middleware.
The token is normally provided in a HTTP header (Eula
), but it
can also be provided in a cookie by setting the opts.cookie
option
to the name of the cookie that contains the token. Custom token retrieval
can also be done through the opts.getEulaToken
option. The provided function
should match the following interface:
1/** 2 * Your custom token resolver 3 * @this The ctx object passed to the middleware 4 * 5 * @param {object} opts The middleware's options 6 * @return {String|null} The resolved token or null if not found 7 */
The resolution order for the token is the following. The first non-empty token resolved will be the one that is verified.
opts.getToken
functionopts.cookie
is set)Normally you provide a single shared secret in opts.secret
, but another
alternative is to have an earlier middleware set ctx.state.secret
,
typically per request. If this property exists, it will be used instead
of the one in opts.secret
.
1var koa = require('koa'); 2var eula = require('koa-eula'); 3 4var app = koa(); 5 6// Custom 403 handling if you don't want to expose koa-eula errors to users 7app.use(function(ctx, next) { 8 return next().catch((err) => { 9 if (401 == err.status) { 10 ctx.status = 401; 11 ctx.body = 'Protected resource, use Eula header to get access\n'; 12 } else { 13 throw err; 14 } 15 }); 16}); 17 18// Unprotected middleware 19app.use(function(ctx, next) { 20 if (ctx.url.match(/^\/public/)) { 21 ctx.body = 'unprotected\n'; 22 } else { 23 return next(); 24 } 25}); 26 27// Middleware below this line is only reached if eula token is valid 28app.use(eula({ secret: 'shared-secret' })); 29 30// Protected middleware 31app.use(function (ctx){ 32 if (ctx.url.match(/^\/api/)) { 33 ctx.body = 'protected\n'; 34 } 35}); 36 37app.listen(3000);
Alternatively you can conditionally run the eula
middleware under certain conditions:
1var koa = require('koa'); 2var eula = require('koa-eula'); 3 4var app = koa(); 5 6// Middleware below this line is only reached if eula token is valid 7// unless the URL starts with '/public' 8app.use(eula({ secret: 'shared-secret' }).unless({ path: [/^\/public/] })); 9 10// Unprotected middleware 11app.use(function *(next){ 12 if (this.url.match(/^\/public/)) { 13 this.body = 'unprotected\n'; 14 } else { 15 yield next; 16 } 17}); 18 19// Protected middleware 20app.use(function *(){ 21 if (this.url.match(/^\/api/)) { 22 this.body = 'protected\n'; 23 } 24}); 25 26app.listen(3000);
For more information on unless
exceptions, check koa-unless.
You can also add the passthrough
option to always yield next,
even if no valid Authorization header was found:
1app.use(eula({ secret: 'shared-secret', passthrough: true }));
This lets downstream middleware make decisions based on whether ctx.state.user
is set.
If you prefer to use another ctx key for the decoded data, just pass in key
, like so:
1app.use(eula({ secret: 'shared-secret', key: 'euladata' }));
This makes the decoded data available as ctx.state.euladata
.
If the tokenKey
option is present, and a valid token is found, the original raw token
is made available to subsequent middleware as ctx.state[opts.tokenKey]
.
You can specify audience and/or issuer as well:
1app.use(eula({ secret: 'shared-secret', 2 audience: 'http://myapi/protected', 3 issuer: 'http://issuer' }));
If the eula has an expiration (exp
), it will be checked.
1npm install 2npm test
This code is largely based on koa-jwt.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
Found 0/9 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
no SAST tool detected
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
41 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-11
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More