@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
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i @cloudflare/util-api

Weekly Downloads

584

Version

1.2.27

License

BSD-3-Clause

Unpacked Size

22.3 kB

Total Files

9

Last publish

Collaborators

  • rexscaria
  • dcruz_cf
  • xuranwang
  • jculvey
  • sejoker
  • cf-radar
  • cf-ci-write
  • segments-write
  • thibmeu
  • xortive
  • gurjinder
  • cf-ci2
  • lvalenta
  • worenga
  • chiminator
  • third774
  • jasnell
  • terinjokes
  • celso
  • jsteinberger
  • gregbrimble
  • asapzacy
  • g4brym
  • wrangler-publisher
  • cf-media-manager
  • dash_service_account
  • jacobbednarz
  • lerwincf
  • simonabadoiu
  • cms1919
  • mgirouard-cf
  • musa-cf
  • vaishakpdinesh
  • ichernetsky-cf
  • jseba_cf
  • gabivlj-cf
  • ganders-cloudflare
  • nsharma-cf
  • mikenomitch
  • tlefebvre_cf
  • nafeezcf
  • eduardo-vargas