@passflow/node 0.0.0-bootstrap.0 → 0.0.0-stage
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -179
- package/package.json +4 -104
- package/LICENSE +0 -21
- package/dist/claims-BHJhnzch.d.cts +0 -51
- package/dist/claims-BHJhnzch.d.mts +0 -51
- package/dist/evaluate-BTuol-Oa.mjs +0 -348
- package/dist/evaluate-C20MecTf.cjs +0 -491
- package/dist/express.cjs +0 -52
- package/dist/express.d.cts +0 -29
- package/dist/express.d.mts +0 -29
- package/dist/express.mjs +0 -49
- package/dist/fastify.cjs +0 -67
- package/dist/fastify.d.cts +0 -40
- package/dist/fastify.d.mts +0 -40
- package/dist/fastify.mjs +0 -63
- package/dist/hono.cjs +0 -51
- package/dist/hono.d.cts +0 -24
- package/dist/hono.d.mts +0 -24
- package/dist/hono.mjs +0 -48
- package/dist/index.cjs +0 -558
- package/dist/index.d.cts +0 -141
- package/dist/index.d.mts +0 -141
- package/dist/index.mjs +0 -539
package/dist/fastify.cjs
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_evaluate = require("./evaluate-C20MecTf.cjs");
|
|
3
|
-
// src/fastify.ts
|
|
4
|
-
function send(reply, decision) {
|
|
5
|
-
if (decision.kind === "reject") reply.code(decision.status).headers(decision.headers).send();
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Hooks for one verifier, with no plugin and no decoration, callable any number of times: the way to use a second
|
|
9
|
-
* verifier on an instance. Each is a `preHandler`-shaped async function. `authenticate` always verifies the presented
|
|
10
|
-
* token and replaces `request.passflow`. `requireACR` and `requireFresh` reuse claims only when this verifier produced
|
|
11
|
-
* that exact object, and otherwise verify the presented token themselves, so a broad instance-level hook followed by
|
|
12
|
-
* a narrow route-level one enforces the narrow verifier's policy. Both throw `TypeError` at construction on an invalid
|
|
13
|
-
* level or limit.
|
|
14
|
-
*/
|
|
15
|
-
function createFastifyHooks(verifier) {
|
|
16
|
-
require_evaluate.assertVerifier(verifier);
|
|
17
|
-
const hook = (reuse, requirement) => async (request, reply) => {
|
|
18
|
-
const existing = reuse ? request.passflow ?? void 0 : void 0;
|
|
19
|
-
const result = await require_evaluate.guard(verifier, request.headers.authorization, existing, requirement);
|
|
20
|
-
if ("reject" in result) {
|
|
21
|
-
send(reply, result.reject);
|
|
22
|
-
return reply;
|
|
23
|
-
}
|
|
24
|
-
request.passflow = result.claims;
|
|
25
|
-
};
|
|
26
|
-
return {
|
|
27
|
-
authenticate: hook(false),
|
|
28
|
-
requireACR: (min) => hook(true, require_evaluate.assertRequirement({
|
|
29
|
-
kind: "acr",
|
|
30
|
-
min
|
|
31
|
-
})),
|
|
32
|
-
requireFresh: (maxAgeSeconds) => hook(true, require_evaluate.assertRequirement({
|
|
33
|
-
kind: "fresh",
|
|
34
|
-
maxAgeSeconds
|
|
35
|
-
}))
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
const plugin = async (fastify, opts) => {
|
|
39
|
-
const hooks = createFastifyHooks(opts.verifier);
|
|
40
|
-
fastify.decorate("passflow", hooks);
|
|
41
|
-
fastify.decorateRequest("passflow", null);
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Decorates the instance with `fastify.passflow` and `request.passflow`, and registers no hook, so routes opt in one
|
|
45
|
-
* at a time and public routes are untouched. Register it at most once per instance: a second registration throws
|
|
46
|
-
* Fastify's own `FST_ERR_DEC_ALREADY_PRESENT`. Use {@link createFastifyHooks} for every further verifier.
|
|
47
|
-
*/
|
|
48
|
-
const passflowFastify = Object.assign(plugin, {
|
|
49
|
-
[Symbol.for("skip-override")]: true,
|
|
50
|
-
[Symbol.for("fastify.display-name")]: "@passflow/node"
|
|
51
|
-
});
|
|
52
|
-
/** The claims a Passflow hook put on this request. Throws `PassflowUsageError` if none ran. */
|
|
53
|
-
function getAuth(request) {
|
|
54
|
-
if (request.passflow === null || request.passflow === void 0) throw new require_evaluate.PassflowUsageError("[passflow] getAuth called before a Passflow hook ran on this request");
|
|
55
|
-
return request.passflow;
|
|
56
|
-
}
|
|
57
|
-
/** Names `WWW-Authenticate` in `@fastify/cors`'s `exposedHeaders`, keeping what is already there. */
|
|
58
|
-
function exposeChallengeHeader(cors) {
|
|
59
|
-
return {
|
|
60
|
-
...cors,
|
|
61
|
-
exposedHeaders: require_evaluate.withChallengeHeader(cors?.exposedHeaders)
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
exports.createFastifyHooks = createFastifyHooks;
|
|
65
|
-
exports.exposeChallengeHeader = exposeChallengeHeader;
|
|
66
|
-
exports.getAuth = getAuth;
|
|
67
|
-
exports.passflowFastify = passflowFastify;
|
package/dist/fastify.d.cts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { r as Verifier, t as PassflowClaims } from "./claims-BHJhnzch.cjs";
|
|
2
|
-
import { FastifyPluginAsync, FastifyRequest, preHandlerAsyncHookHandler } from "fastify";
|
|
3
|
-
export type PassflowFastifyHooks = {
|
|
4
|
-
authenticate: preHandlerAsyncHookHandler;
|
|
5
|
-
requireACR(min: string): preHandlerAsyncHookHandler;
|
|
6
|
-
requireFresh(maxAgeSeconds: number): preHandlerAsyncHookHandler;
|
|
7
|
-
};
|
|
8
|
-
declare module 'fastify' {
|
|
9
|
-
interface FastifyInstance {
|
|
10
|
-
passflow: PassflowFastifyHooks;
|
|
11
|
-
}
|
|
12
|
-
interface FastifyRequest {
|
|
13
|
-
passflow: PassflowClaims | null;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Hooks for one verifier, with no plugin and no decoration, callable any number of times: the way to use a second
|
|
18
|
-
* verifier on an instance. Each is a `preHandler`-shaped async function. `authenticate` always verifies the presented
|
|
19
|
-
* token and replaces `request.passflow`. `requireACR` and `requireFresh` reuse claims only when this verifier produced
|
|
20
|
-
* that exact object, and otherwise verify the presented token themselves, so a broad instance-level hook followed by
|
|
21
|
-
* a narrow route-level one enforces the narrow verifier's policy. Both throw `TypeError` at construction on an invalid
|
|
22
|
-
* level or limit.
|
|
23
|
-
*/
|
|
24
|
-
export declare function createFastifyHooks(verifier: Verifier): PassflowFastifyHooks;
|
|
25
|
-
/**
|
|
26
|
-
* Decorates the instance with `fastify.passflow` and `request.passflow`, and registers no hook, so routes opt in one
|
|
27
|
-
* at a time and public routes are untouched. Register it at most once per instance: a second registration throws
|
|
28
|
-
* Fastify's own `FST_ERR_DEC_ALREADY_PRESENT`. Use {@link createFastifyHooks} for every further verifier.
|
|
29
|
-
*/
|
|
30
|
-
export declare const passflowFastify: FastifyPluginAsync<{
|
|
31
|
-
verifier: Verifier;
|
|
32
|
-
}>;
|
|
33
|
-
/** The claims a Passflow hook put on this request. Throws `PassflowUsageError` if none ran. */
|
|
34
|
-
export declare function getAuth(request: Pick<FastifyRequest, 'passflow'>): PassflowClaims;
|
|
35
|
-
/** Names `WWW-Authenticate` in `@fastify/cors`'s `exposedHeaders`, keeping what is already there. */
|
|
36
|
-
export declare function exposeChallengeHeader<T extends object>(cors: T & {
|
|
37
|
-
exposedHeaders?: string | string[];
|
|
38
|
-
}): Omit<T, 'exposedHeaders'> & {
|
|
39
|
-
exposedHeaders: string[];
|
|
40
|
-
};
|
package/dist/fastify.d.mts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { r as Verifier, t as PassflowClaims } from "./claims-BHJhnzch.mjs";
|
|
2
|
-
import { FastifyPluginAsync, FastifyRequest, preHandlerAsyncHookHandler } from "fastify";
|
|
3
|
-
export type PassflowFastifyHooks = {
|
|
4
|
-
authenticate: preHandlerAsyncHookHandler;
|
|
5
|
-
requireACR(min: string): preHandlerAsyncHookHandler;
|
|
6
|
-
requireFresh(maxAgeSeconds: number): preHandlerAsyncHookHandler;
|
|
7
|
-
};
|
|
8
|
-
declare module 'fastify' {
|
|
9
|
-
interface FastifyInstance {
|
|
10
|
-
passflow: PassflowFastifyHooks;
|
|
11
|
-
}
|
|
12
|
-
interface FastifyRequest {
|
|
13
|
-
passflow: PassflowClaims | null;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Hooks for one verifier, with no plugin and no decoration, callable any number of times: the way to use a second
|
|
18
|
-
* verifier on an instance. Each is a `preHandler`-shaped async function. `authenticate` always verifies the presented
|
|
19
|
-
* token and replaces `request.passflow`. `requireACR` and `requireFresh` reuse claims only when this verifier produced
|
|
20
|
-
* that exact object, and otherwise verify the presented token themselves, so a broad instance-level hook followed by
|
|
21
|
-
* a narrow route-level one enforces the narrow verifier's policy. Both throw `TypeError` at construction on an invalid
|
|
22
|
-
* level or limit.
|
|
23
|
-
*/
|
|
24
|
-
export declare function createFastifyHooks(verifier: Verifier): PassflowFastifyHooks;
|
|
25
|
-
/**
|
|
26
|
-
* Decorates the instance with `fastify.passflow` and `request.passflow`, and registers no hook, so routes opt in one
|
|
27
|
-
* at a time and public routes are untouched. Register it at most once per instance: a second registration throws
|
|
28
|
-
* Fastify's own `FST_ERR_DEC_ALREADY_PRESENT`. Use {@link createFastifyHooks} for every further verifier.
|
|
29
|
-
*/
|
|
30
|
-
export declare const passflowFastify: FastifyPluginAsync<{
|
|
31
|
-
verifier: Verifier;
|
|
32
|
-
}>;
|
|
33
|
-
/** The claims a Passflow hook put on this request. Throws `PassflowUsageError` if none ran. */
|
|
34
|
-
export declare function getAuth(request: Pick<FastifyRequest, 'passflow'>): PassflowClaims;
|
|
35
|
-
/** Names `WWW-Authenticate` in `@fastify/cors`'s `exposedHeaders`, keeping what is already there. */
|
|
36
|
-
export declare function exposeChallengeHeader<T extends object>(cors: T & {
|
|
37
|
-
exposedHeaders?: string | string[];
|
|
38
|
-
}): Omit<T, 'exposedHeaders'> & {
|
|
39
|
-
exposedHeaders: string[];
|
|
40
|
-
};
|
package/dist/fastify.mjs
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { a as guard, d as withChallengeHeader, n as assertVerifier, s as PassflowUsageError, t as assertRequirement } from "./evaluate-BTuol-Oa.mjs";
|
|
2
|
-
// src/fastify.ts
|
|
3
|
-
function send(reply, decision) {
|
|
4
|
-
if (decision.kind === "reject") reply.code(decision.status).headers(decision.headers).send();
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Hooks for one verifier, with no plugin and no decoration, callable any number of times: the way to use a second
|
|
8
|
-
* verifier on an instance. Each is a `preHandler`-shaped async function. `authenticate` always verifies the presented
|
|
9
|
-
* token and replaces `request.passflow`. `requireACR` and `requireFresh` reuse claims only when this verifier produced
|
|
10
|
-
* that exact object, and otherwise verify the presented token themselves, so a broad instance-level hook followed by
|
|
11
|
-
* a narrow route-level one enforces the narrow verifier's policy. Both throw `TypeError` at construction on an invalid
|
|
12
|
-
* level or limit.
|
|
13
|
-
*/
|
|
14
|
-
function createFastifyHooks(verifier) {
|
|
15
|
-
assertVerifier(verifier);
|
|
16
|
-
const hook = (reuse, requirement) => async (request, reply) => {
|
|
17
|
-
const existing = reuse ? request.passflow ?? void 0 : void 0;
|
|
18
|
-
const result = await guard(verifier, request.headers.authorization, existing, requirement);
|
|
19
|
-
if ("reject" in result) {
|
|
20
|
-
send(reply, result.reject);
|
|
21
|
-
return reply;
|
|
22
|
-
}
|
|
23
|
-
request.passflow = result.claims;
|
|
24
|
-
};
|
|
25
|
-
return {
|
|
26
|
-
authenticate: hook(false),
|
|
27
|
-
requireACR: (min) => hook(true, assertRequirement({
|
|
28
|
-
kind: "acr",
|
|
29
|
-
min
|
|
30
|
-
})),
|
|
31
|
-
requireFresh: (maxAgeSeconds) => hook(true, assertRequirement({
|
|
32
|
-
kind: "fresh",
|
|
33
|
-
maxAgeSeconds
|
|
34
|
-
}))
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
const plugin = async (fastify, opts) => {
|
|
38
|
-
const hooks = createFastifyHooks(opts.verifier);
|
|
39
|
-
fastify.decorate("passflow", hooks);
|
|
40
|
-
fastify.decorateRequest("passflow", null);
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Decorates the instance with `fastify.passflow` and `request.passflow`, and registers no hook, so routes opt in one
|
|
44
|
-
* at a time and public routes are untouched. Register it at most once per instance: a second registration throws
|
|
45
|
-
* Fastify's own `FST_ERR_DEC_ALREADY_PRESENT`. Use {@link createFastifyHooks} for every further verifier.
|
|
46
|
-
*/
|
|
47
|
-
const passflowFastify = Object.assign(plugin, {
|
|
48
|
-
[Symbol.for("skip-override")]: true,
|
|
49
|
-
[Symbol.for("fastify.display-name")]: "@passflow/node"
|
|
50
|
-
});
|
|
51
|
-
/** The claims a Passflow hook put on this request. Throws `PassflowUsageError` if none ran. */
|
|
52
|
-
function getAuth(request) {
|
|
53
|
-
if (request.passflow === null || request.passflow === void 0) throw new PassflowUsageError("[passflow] getAuth called before a Passflow hook ran on this request");
|
|
54
|
-
return request.passflow;
|
|
55
|
-
}
|
|
56
|
-
/** Names `WWW-Authenticate` in `@fastify/cors`'s `exposedHeaders`, keeping what is already there. */
|
|
57
|
-
function exposeChallengeHeader(cors) {
|
|
58
|
-
return {
|
|
59
|
-
...cors,
|
|
60
|
-
exposedHeaders: withChallengeHeader(cors?.exposedHeaders)
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
export { createFastifyHooks, exposeChallengeHeader, getAuth, passflowFastify };
|
package/dist/hono.cjs
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_evaluate = require("./evaluate-C20MecTf.cjs");
|
|
3
|
-
// src/hono.ts
|
|
4
|
-
/** `c.body` rather than a thrown HTTPException, so headers `hono/cors` already set survive the rejection. */
|
|
5
|
-
function send(c, decision) {
|
|
6
|
-
const { status, headers } = decision;
|
|
7
|
-
return c.body(null, status, headers);
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Hono middleware, for any runtime with WebCrypto and fetch. `authenticate` always verifies the presented token and
|
|
11
|
-
* replaces the `passflow` variable. `requireACR` and `requireFresh` work alone: they reuse claims only when this verifier
|
|
12
|
-
* produced that exact object, and otherwise verify the presented token themselves. Both throw `TypeError` at construction
|
|
13
|
-
* on an invalid level or limit.
|
|
14
|
-
*/
|
|
15
|
-
function passflowHono(verifier) {
|
|
16
|
-
require_evaluate.assertVerifier(verifier);
|
|
17
|
-
const middleware = (reuse, requirement) => async (c, next) => {
|
|
18
|
-
const existing = reuse ? c.get("passflow") : void 0;
|
|
19
|
-
const result = await require_evaluate.guard(verifier, c.req.header("authorization"), existing, requirement);
|
|
20
|
-
if ("reject" in result) return send(c, result.reject);
|
|
21
|
-
c.set("passflow", result.claims);
|
|
22
|
-
await next();
|
|
23
|
-
};
|
|
24
|
-
return {
|
|
25
|
-
authenticate: middleware(false),
|
|
26
|
-
requireACR: (min) => middleware(true, require_evaluate.assertRequirement({
|
|
27
|
-
kind: "acr",
|
|
28
|
-
min
|
|
29
|
-
})),
|
|
30
|
-
requireFresh: (maxAgeSeconds) => middleware(true, require_evaluate.assertRequirement({
|
|
31
|
-
kind: "fresh",
|
|
32
|
-
maxAgeSeconds
|
|
33
|
-
}))
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
/** The claims a Passflow middleware put on this context. Throws `PassflowUsageError` if none ran. */
|
|
37
|
-
function getAuth(c) {
|
|
38
|
-
const claims = c.get("passflow");
|
|
39
|
-
if (claims === void 0 || claims === null) throw new require_evaluate.PassflowUsageError("[passflow] getAuth called before a Passflow middleware ran on this request");
|
|
40
|
-
return claims;
|
|
41
|
-
}
|
|
42
|
-
/** Names `WWW-Authenticate` in `hono/cors`'s `exposeHeaders`, keeping what is already there. */
|
|
43
|
-
function exposeChallengeHeader(cors) {
|
|
44
|
-
return {
|
|
45
|
-
...cors,
|
|
46
|
-
exposeHeaders: require_evaluate.withChallengeHeader(cors?.exposeHeaders)
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
exports.exposeChallengeHeader = exposeChallengeHeader;
|
|
50
|
-
exports.getAuth = getAuth;
|
|
51
|
-
exports.passflowHono = passflowHono;
|
package/dist/hono.d.cts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { r as Verifier, t as PassflowClaims } from "./claims-BHJhnzch.cjs";
|
|
2
|
-
import { Context, MiddlewareHandler } from "hono";
|
|
3
|
-
export type PassflowVariables = {
|
|
4
|
-
passflow: PassflowClaims;
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* Hono middleware, for any runtime with WebCrypto and fetch. `authenticate` always verifies the presented token and
|
|
8
|
-
* replaces the `passflow` variable. `requireACR` and `requireFresh` work alone: they reuse claims only when this verifier
|
|
9
|
-
* produced that exact object, and otherwise verify the presented token themselves. Both throw `TypeError` at construction
|
|
10
|
-
* on an invalid level or limit.
|
|
11
|
-
*/
|
|
12
|
-
export declare function passflowHono(verifier: Verifier): {
|
|
13
|
-
authenticate: MiddlewareHandler;
|
|
14
|
-
requireACR(min: string): MiddlewareHandler;
|
|
15
|
-
requireFresh(maxAgeSeconds: number): MiddlewareHandler;
|
|
16
|
-
};
|
|
17
|
-
/** The claims a Passflow middleware put on this context. Throws `PassflowUsageError` if none ran. */
|
|
18
|
-
export declare function getAuth(c: Context): PassflowClaims;
|
|
19
|
-
/** Names `WWW-Authenticate` in `hono/cors`'s `exposeHeaders`, keeping what is already there. */
|
|
20
|
-
export declare function exposeChallengeHeader<T extends object>(cors: T & {
|
|
21
|
-
exposeHeaders?: string[];
|
|
22
|
-
}): Omit<T, 'exposeHeaders'> & {
|
|
23
|
-
exposeHeaders: string[];
|
|
24
|
-
};
|
package/dist/hono.d.mts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { r as Verifier, t as PassflowClaims } from "./claims-BHJhnzch.mjs";
|
|
2
|
-
import { Context, MiddlewareHandler } from "hono";
|
|
3
|
-
export type PassflowVariables = {
|
|
4
|
-
passflow: PassflowClaims;
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* Hono middleware, for any runtime with WebCrypto and fetch. `authenticate` always verifies the presented token and
|
|
8
|
-
* replaces the `passflow` variable. `requireACR` and `requireFresh` work alone: they reuse claims only when this verifier
|
|
9
|
-
* produced that exact object, and otherwise verify the presented token themselves. Both throw `TypeError` at construction
|
|
10
|
-
* on an invalid level or limit.
|
|
11
|
-
*/
|
|
12
|
-
export declare function passflowHono(verifier: Verifier): {
|
|
13
|
-
authenticate: MiddlewareHandler;
|
|
14
|
-
requireACR(min: string): MiddlewareHandler;
|
|
15
|
-
requireFresh(maxAgeSeconds: number): MiddlewareHandler;
|
|
16
|
-
};
|
|
17
|
-
/** The claims a Passflow middleware put on this context. Throws `PassflowUsageError` if none ran. */
|
|
18
|
-
export declare function getAuth(c: Context): PassflowClaims;
|
|
19
|
-
/** Names `WWW-Authenticate` in `hono/cors`'s `exposeHeaders`, keeping what is already there. */
|
|
20
|
-
export declare function exposeChallengeHeader<T extends object>(cors: T & {
|
|
21
|
-
exposeHeaders?: string[];
|
|
22
|
-
}): Omit<T, 'exposeHeaders'> & {
|
|
23
|
-
exposeHeaders: string[];
|
|
24
|
-
};
|
package/dist/hono.mjs
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { a as guard, d as withChallengeHeader, n as assertVerifier, s as PassflowUsageError, t as assertRequirement } from "./evaluate-BTuol-Oa.mjs";
|
|
2
|
-
// src/hono.ts
|
|
3
|
-
/** `c.body` rather than a thrown HTTPException, so headers `hono/cors` already set survive the rejection. */
|
|
4
|
-
function send(c, decision) {
|
|
5
|
-
const { status, headers } = decision;
|
|
6
|
-
return c.body(null, status, headers);
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Hono middleware, for any runtime with WebCrypto and fetch. `authenticate` always verifies the presented token and
|
|
10
|
-
* replaces the `passflow` variable. `requireACR` and `requireFresh` work alone: they reuse claims only when this verifier
|
|
11
|
-
* produced that exact object, and otherwise verify the presented token themselves. Both throw `TypeError` at construction
|
|
12
|
-
* on an invalid level or limit.
|
|
13
|
-
*/
|
|
14
|
-
function passflowHono(verifier) {
|
|
15
|
-
assertVerifier(verifier);
|
|
16
|
-
const middleware = (reuse, requirement) => async (c, next) => {
|
|
17
|
-
const existing = reuse ? c.get("passflow") : void 0;
|
|
18
|
-
const result = await guard(verifier, c.req.header("authorization"), existing, requirement);
|
|
19
|
-
if ("reject" in result) return send(c, result.reject);
|
|
20
|
-
c.set("passflow", result.claims);
|
|
21
|
-
await next();
|
|
22
|
-
};
|
|
23
|
-
return {
|
|
24
|
-
authenticate: middleware(false),
|
|
25
|
-
requireACR: (min) => middleware(true, assertRequirement({
|
|
26
|
-
kind: "acr",
|
|
27
|
-
min
|
|
28
|
-
})),
|
|
29
|
-
requireFresh: (maxAgeSeconds) => middleware(true, assertRequirement({
|
|
30
|
-
kind: "fresh",
|
|
31
|
-
maxAgeSeconds
|
|
32
|
-
}))
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
/** The claims a Passflow middleware put on this context. Throws `PassflowUsageError` if none ran. */
|
|
36
|
-
function getAuth(c) {
|
|
37
|
-
const claims = c.get("passflow");
|
|
38
|
-
if (claims === void 0 || claims === null) throw new PassflowUsageError("[passflow] getAuth called before a Passflow middleware ran on this request");
|
|
39
|
-
return claims;
|
|
40
|
-
}
|
|
41
|
-
/** Names `WWW-Authenticate` in `hono/cors`'s `exposeHeaders`, keeping what is already there. */
|
|
42
|
-
function exposeChallengeHeader(cors) {
|
|
43
|
-
return {
|
|
44
|
-
...cors,
|
|
45
|
-
exposeHeaders: withChallengeHeader(cors?.exposeHeaders)
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
export { exposeChallengeHeader, getAuth, passflowHono };
|