1.2.27 • Published 3 years ago
@cloudflare/util-api v1.2.27
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
}
}
1.2.27
3 years ago
1.2.26
4 years ago
1.2.24
4 years ago
1.2.25
4 years ago
1.2.23
4 years ago
1.2.21
5 years ago
1.2.22
5 years ago
1.2.20
5 years ago
1.2.19
5 years ago
1.2.18
5 years ago
1.2.17
5 years ago
1.2.16
5 years ago
1.2.15
5 years ago
1.2.14
5 years ago
1.2.12
5 years ago
1.2.10
5 years ago
1.2.9
5 years ago
1.2.8
5 years ago
1.2.7
5 years ago
1.2.6
5 years ago
1.2.5
5 years ago
1.2.4
5 years ago
1.2.3
5 years ago
1.2.1
5 years ago
1.2.0
5 years ago
1.1.0
5 years ago