@cloudflare/util-api
TypeScript icon, indicating that this package has built-in type declarations

1.2.27 • Public • Published

util-api

Handy utilities to help interact with the v4 API.

Lightweight. Asynchronous. In TypeScript.

Installation

$ npm install @cloudflare/util-api

Usage

Assuming your node service/worker is behind api-gateway:

import { apiGateway } from '@cloudflare/util-api';

async function handleRequest(request: Request) {
  try {
    const decodedJWT = await apiGateway.authenticateRequest(request);

    console.log(decodedJWT.user.email);
  } catch (e) {
    // Authentication failed
  }
}

If you only have a Bearer token:

import { apiGateway } from '@cloudflare/util-api';

async function handleBearer(bearer: string) {
  try {
    const decodedJWT = await apiGateway.authenticateBearer(bearer);

    console.log(decodedJWT.user.email);
  } catch (e) {
    // Authentication failed
  }
}

If you only have a JWT:

import { apiGateway } from '@cloudflare/util-api';

async function handleJWT(jwt: string) {
  try {
    const decodedJWT = await apiGateway.authenticateJWT(jwt);

    console.log(decodedJWT.user.email);
  } catch (e) {
    // Authentication failed
  }
}

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.2.27
    900
    • latest

Version History

Package Sidebar

Install

npm i @cloudflare/util-api

Weekly Downloads

900

Version

1.2.27

License

BSD-3-Clause

Unpacked Size

22.3 kB

Total Files

9

Last publish

Collaborators

  • cf-media-manager
  • jacobbednarz
  • celso
  • cf-radar
  • dash_service_account
  • g4brym
  • snigdha34
  • wrangler-publisher
  • marksteyn
  • chiminator
  • sgoodhew_cf
  • terinjokes
  • third774
  • jsteinberger
  • jasnell
  • asapzacy
  • pcostanzo
  • gregbrimble
  • geelen
  • rexscaria
  • dcruz_cf
  • xuranwang
  • jculvey
  • sejoker
  • vasturiano
  • cf-ci-write
  • segments-write
  • thibmeu
  • xortive
  • gurjinder
  • cf-ci2
  • lvalenta
  • worenga