North Pittsburgh Meatpackers

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

    Keywords

    none

    Install

    npm i @cloudflare/util-api

    DownloadsWeekly Downloads

    753

    Version

    1.2.27

    License

    BSD-3-Clause

    Unpacked Size

    22.3 kB

    Total Files

    9

    Last publish

    Collaborators

    • trevorcf
    • g4brym
    • snigdha34
    • wrangler-publisher
    • marksteyn
    • chiminator
    • sgoodhew_cf
    • terinjokes
    • third774
    • evanderkoogh
    • jsteinberger
    • jasnell
    • kkoenig
    • asapzacy
    • pcostanzo
    • gregbrimble
    • geelen
    • jgentes
    • rexscaria
    • dcruz_cf
    • xuranwang
    • jculvey
    • sejoker
    • caass
    • vasturiano
    • cf-ci-write
    • segments-write
    • thibmeu
    • xortive
    • gurjinder
    • cf-ci2
    • lvalenta
    • worenga