MCPcopy Create free account
hub / github.com/fontsource/fontsource / verifyAuth

Function verifyAuth

api/upload/src/auth.ts:3–18  ·  view source on GitHub ↗
(request: Request, env: Env)

Source from the content-addressed store, hash-verified

1import { StatusError } from 'itty-router';
2
3export const verifyAuth = (request: Request, env: Env) => {
4 const authHeader = request.headers.get('Authorization');
5 if (!authHeader) {
6 throw new StatusError(401, 'Unauthorized. Missing authorization header.');
7 }
8 const [scheme, encoded] = authHeader.split(' ');
9
10 // The Authorization header must start with Bearer, followed by a space.
11 if (!encoded || scheme !== 'Bearer') {
12 throw new StatusError(400, 'Bad Request. Malformed authorization header.');
13 }
14
15 if (encoded !== env.UPLOAD_KEY) {
16 throw new StatusError(401, 'Unauthorized. Invalid authorization token.');
17 }
18};

Callers

nothing calls this directly

Calls 1

getMethod · 0.65

Tested by

no test coverage detected