1.2.27 • Published 2 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
2 years ago
1.2.26
3 years ago
1.2.24
3 years ago
1.2.25
3 years ago
1.2.23
3 years ago
1.2.21
3 years ago
1.2.22
3 years ago
1.2.20
3 years ago
1.2.19
4 years ago
1.2.18
4 years ago
1.2.17
4 years ago
1.2.16
4 years ago
1.2.15
4 years ago
1.2.14
4 years ago
1.2.12
4 years ago
1.2.10
4 years ago
1.2.9
4 years ago
1.2.8
4 years ago
1.2.7
4 years ago
1.2.6
4 years ago
1.2.5
4 years ago
1.2.4
4 years ago
1.2.3
4 years ago
1.2.1
4 years ago
1.2.0
4 years ago
1.1.0
4 years ago