# @yingyeothon/aws-lambda-jwt-custom-authorizer

> Simple custom authorizer using JWT for AWS API Gateway

Latest version **0.2.1** (published 2019-11-24) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @yingyeothon/aws-lambda-jwt-custom-authorizer
pnpm add @yingyeothon/aws-lambda-jwt-custom-authorizer
yarn add @yingyeothon/aws-lambda-jwt-custom-authorizer
bun add @yingyeothon/aws-lambda-jwt-custom-authorizer
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2019-11-24 |
| First published | 2019-07-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 7.8 KB |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | jaeyoung.choi |
| Maintainers | lacti |
| Keywords | serverless, jwt, auth |

## Links

- npm: https://www.npmjs.com/package/@yingyeothon/aws-lambda-jwt-custom-authorizer
- Repository: https://github.com/yingyeothon/nodejs-toolkit
- Homepage: https://github.com/yingyeothon/nodejs-lambda-authorizer/tree/master/packages/aws-lambda-jwt-custom-authorizer
- Issues: https://github.com/yingyeothon/nodejs-toolkit/issues
- npm.io page: https://npm.io/package/@yingyeothon/aws-lambda-jwt-custom-authorizer

## Dependencies (3)

- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^8.5.1
- [@yingyeothon/logger](https://npm.io/package/@yingyeothon/logger.md) ^0.2.0
- [@yingyeothon/aws-lambda-custom-authorizer](https://npm.io/package/@yingyeothon/aws-lambda-custom-authorizer.md) ^0.2.1

## Alternatives

- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads
- [escher-request](https://npm.io/package/escher-request.md) — 545 weekly downloads

## Recent versions

- 0.2.1 (latest) — 2019-11-24
- 0.2.0 — 2019-11-15
- 0.1.0 — 2019-07-31

## README

# AWS Lambda custom authorizer with JWT

A simple function to build easily AWS Lambda custom authorizer with JWT.

## Usage

```typescript
import buildAuthorizer from "@yingyeothon/aws-lambda-jwt-custom-authorizer";
import { CustomAuthorizerHandler } from "aws-lambda";

// Define the custom authorizer.
export const auth: CustomAuthorizerHandler = buildAuthorizer({
  jwtSecret: "verySecret",
  login: async ({ id, password }) => {
    // Define only the login method.
    return id === "admin" && password === "1234";
  }
  // jwtExpiresIn: "30m", // The expiration of that JWT.
  // buildJWTPayload: ({ id, password }) => ({ id } as any), // A function to build a payload that is in JWT.
  // logger: nullLogger
});

// Define an actual HTTP handler.
export const hello: APIGatewayProxyHandler = async event => {
  // This handler is called only if "auth" Lambda generates a policy document to allow a request.
  // That is, if "auth" denies a request, this handler wouldn't be called.
  // "event.requestContext.authorizer" is { token: JWT } from "auth" method.
  return {
    statusCode: 200,
    body: JSON.stringify(event.requestContext.authorizer)
  };
};
```

---
_Source: https://npm.io/package/@yingyeothon/aws-lambda-jwt-custom-authorizer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
