Gathering detailed insights and metrics for middy-middleware-jwt-auth
Gathering detailed insights and metrics for middy-middleware-jwt-auth
Gathering detailed insights and metrics for middy-middleware-jwt-auth
Gathering detailed insights and metrics for middy-middleware-jwt-auth
npm install middy-middleware-jwt-auth
Typescript
Module System
Node Version
NPM Version
69.3
Supply Chain
97.3
Quality
73.5
Maintenance
100
Vulnerability
98.6
License
TypeScript (94.88%)
JavaScript (5.12%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
229,292
Last Day
191
Last Week
784
Last Month
3,922
Last Year
60,858
MIT License
25 Stars
685 Commits
8 Forks
3 Watchers
4 Branches
6 Contributors
Updated on Oct 18, 2024
Minified
Minified + Gzipped
Latest Version
6.1.0
Package Id
middy-middleware-jwt-auth@6.1.0
Unpacked Size
39.16 kB
Size
10.48 kB
File Count
15
NPM Version
8.19.4
Node Version
16.20.2
Published on
Jan 27, 2024
Cumulative downloads
Total Downloads
Last Day
-17%
191
Compared to previous day
Last Week
-20.1%
784
Compared to previous week
Last Month
31.4%
3,922
Compared to previous month
Last Year
-1.8%
60,858
Compared to previous year
4
1
40
A middy JSON web token authorization middleware inspired by express-jwt.
Download node at nodejs.org and install it, if you haven't already.
1npm install middy-middleware-jwt-auth --save
There is additional documentation.
1import createHttpError from "http-errors"; 2import middy from "@middy/core"; 3import httpErrorHandler from "@middy/http-error-handler"; 4import httpHeaderNormalizer from "@middy/http-header-normalizer"; 5import JWTAuthMiddleware, { 6 EncryptionAlgorithms, 7 IAuthorizedEvent, 8} from "middy-middleware-jwt-auth"; 9 10// Optionally define the token payload you expect to receive 11interface ITokenPayload { 12 permissions: string[]; 13} 14 15// Optionally define a type guard for the token payload 16function isTokenPayload(token: any): token is ITokenPayload { 17 return ( 18 token != null && 19 Array.isArray(token.permissions) && 20 token.permissions.every((permission: any) => typeof permission === "string") 21 ); 22} 23 24// This is your AWS handler 25const helloWorld = async (event: IAuthorizedEvent<ITokenPayload>) => { 26 // The middleware adds auth information if a valid token was added 27 // If no auth was found and credentialsRequired is set to true, a 401 will be thrown. If auth exists you 28 // have to check that it has the expected form. 29 if (event.auth!.payload.permissions.indexOf("helloWorld") === -1) { 30 throw createHttpError( 31 403, 32 `User not authorized for helloWorld, only found permissions [${event.auth!.permissions.join(", ")}]`, 33 { 34 type: "NotAuthorized", 35 }, 36 ); 37 } 38 39 return { 40 body: JSON.stringify({ 41 data: `Hello world! Here's your token: ${event.auth!.token}`, 42 }), 43 statusCode: 200, 44 }; 45}; 46 47// Let's "middyfy" our handler, then we will be able to attach middlewares to it 48export const handler = middy(helloWorld) 49 .use(httpHeaderNormalizer()) // Make sure authorization header is saved in lower case 50 .use(httpErrorHandler()) // This middleware is needed do handle the errors thrown by the JWTAuthMiddleware 51 .use( 52 JWTAuthMiddleware({ 53 /** Algorithm to verify JSON web token signature */ 54 algorithm: EncryptionAlgorithms.HS256, 55 /** An optional boolean that enables making authorization mandatory */ 56 credentialsRequired: true, 57 /** An optional function that checks whether the token payload is formatted correctly */ 58 isPayload: isTokenPayload, 59 /** A string or buffer containing either the secret for HMAC algorithms, or the PEM encoded public key for RSA and ECDSA */ 60 secretOrPublicKey: "secret", 61 /** 62 * An optional function used to search for a token e. g. in a query string. By default, and as a fall back, 63 * event.headers.authorization and event.headers.Authorization are used. 64 */ 65 tokenSource: (event: any) => event.queryStringParameters.token, 66 }), 67 );
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
9 existing vulnerabilities detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/6 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-02-10
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