# @blenz/middy-authorizer-middleware

> JWT token validation

Latest version **1.0.11** (published 2020-06-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @blenz/middy-authorizer-middleware
pnpm add @blenz/middy-authorizer-middleware
yarn add @blenz/middy-authorizer-middleware
bun add @blenz/middy-authorizer-middleware
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.11 |
| Published | 2020-06-27 |
| First published | 2020-06-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 17.9 KB |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| Author | Sudo.X LLC |
| Maintainers | blenz |

## Links

- npm: https://www.npmjs.com/package/@blenz/middy-authorizer-middleware
- npm.io page: https://npm.io/package/@blenz/middy-authorizer-middleware

## Dependencies (4)

- [jwks-rsa](https://npm.io/package/jwks-rsa.md) ^1.8.0
- [@middy/core](https://npm.io/package/@middy/core.md) ^1.0.0
- [http-errors](https://npm.io/package/http-errors.md) ^1.7.3
- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^8.5.1

## Recent versions

- 1.0.11 (latest) — 2020-06-27
- 1.0.10 — 2020-06-26
- 1.0.9 — 2020-06-26
- 1.0.8 — 2020-06-25
- 1.0.7 — 2020-06-23
- 1.0.6 — 2020-06-13
- 1.0.5 — 2020-06-07
- 1.0.4 — 2020-06-07
- 1.0.3 — 2020-06-07
- 1.0.2 — 2020-06-07
- 1.0.1 — 2020-06-07
- 1.0.0 — 2020-06-07

## README

# Authenticator

Implements [`middy v1.x` AWS Lambda Middleware](https://github.com/middyjs/middy/tree/1.0.0-beta) to provide token authentication to serverless endpoints.

## Implementation

Run `npm install @middy/core` to add middy to your project.

Run `npm install @mosure/lambda-auth-middleware` to install to your project.

Run `npm install @middy/http-error-handler` to install the error handler.

To implement this middleware into your AWS Lambda follow the code sample below:

```typescript
import { Context, APIGatewayProxyResult, APIGatwayProxyCallback } from 'aws-lambda';
import middy from '@middy/core';
import httpErrorHandler from '@middy/http-error-handler';

import { authorize, AuthMiddlewareConfig } from '@mosure/lambda-auth-middleware';


// Optional token payload and validator
interface TokenPayload {
    somePayloadValue: string;
}

const isPayload = (payload: any): payload is TokenPayload => {
    return payload && payload['somePayloadValue'];
}

// Your AWS Lambda function
const myLambdaFunction = (event: AuthEvent<TokenPayload>, context: Context, callback: APIGatewayProxyCallback) => {
    // Optionally access JWT payload
    if (event.auth.payload.somePayloadValue !== 'TEST') {
        // TODO: handle bad payload
    }

    // TODO: Business Logic (post-authentication)
};

const authConfig: AuthMiddlewareConfig = {
    credentialsRequired: !process.env.NODE_DEBUG, // Force authorization header to exist
    secret: process.env.JWT_SECRET,
    algorithm: 'HS256',
    audience: process.env.JWT_AUDIENCE,
    isPayload
};

const handler = middy(myLambdaFunction)
    .use(httpErrorHandler())
    .use(authorize(authConfig));
```

---
_Source: https://npm.io/package/@blenz/middy-authorizer-middleware · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
