cloudflare-access 1.0.0
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/LICENSE +21 -0
- package/README.md +452 -0
- package/dist/adapters/effect/index.d.mts +167 -0
- package/dist/adapters/effect/index.d.ts +167 -0
- package/dist/adapters/effect/index.js +221 -0
- package/dist/adapters/effect/index.js.map +1 -0
- package/dist/adapters/effect/index.mjs +221 -0
- package/dist/adapters/effect/index.mjs.map +1 -0
- package/dist/adapters/express/index.d.mts +74 -0
- package/dist/adapters/express/index.d.ts +74 -0
- package/dist/adapters/express/index.js +129 -0
- package/dist/adapters/express/index.js.map +1 -0
- package/dist/adapters/express/index.mjs +129 -0
- package/dist/adapters/express/index.mjs.map +1 -0
- package/dist/adapters/fastify/index.d.mts +111 -0
- package/dist/adapters/fastify/index.d.ts +111 -0
- package/dist/adapters/fastify/index.js +140 -0
- package/dist/adapters/fastify/index.js.map +1 -0
- package/dist/adapters/fastify/index.mjs +140 -0
- package/dist/adapters/fastify/index.mjs.map +1 -0
- package/dist/adapters/hono/index.d.mts +19 -0
- package/dist/adapters/hono/index.d.ts +19 -0
- package/dist/adapters/hono/index.js +45 -0
- package/dist/adapters/hono/index.js.map +1 -0
- package/dist/adapters/hono/index.mjs +45 -0
- package/dist/adapters/hono/index.mjs.map +1 -0
- package/dist/adapters/nestjs/index.d.mts +123 -0
- package/dist/adapters/nestjs/index.d.ts +123 -0
- package/dist/adapters/nestjs/index.js +117 -0
- package/dist/adapters/nestjs/index.js.map +1 -0
- package/dist/adapters/nestjs/index.mjs +117 -0
- package/dist/adapters/nestjs/index.mjs.map +1 -0
- package/dist/chunk-DM2KGIQX.mjs +320 -0
- package/dist/chunk-DM2KGIQX.mjs.map +1 -0
- package/dist/chunk-LQWCGHLJ.mjs +108 -0
- package/dist/chunk-LQWCGHLJ.mjs.map +1 -0
- package/dist/chunk-PMFPT3SI.js +108 -0
- package/dist/chunk-PMFPT3SI.js.map +1 -0
- package/dist/chunk-WUJPWM4T.js +320 -0
- package/dist/chunk-WUJPWM4T.js.map +1 -0
- package/dist/config-D4O7DXNT.d.mts +12 -0
- package/dist/config-ottUdc-K.d.ts +12 -0
- package/dist/core/index.d.mts +24 -0
- package/dist/core/index.d.ts +24 -0
- package/dist/core/index.js +41 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/index.mjs +41 -0
- package/dist/core/index.mjs.map +1 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +41 -0
- package/dist/index.mjs.map +1 -0
- package/dist/jwks-ChdyyS_L.d.mts +173 -0
- package/dist/jwks-ChdyyS_L.d.ts +173 -0
- package/dist/middleware-BDl6jUCu.d.mts +83 -0
- package/dist/middleware-CgFsjM20.d.ts +83 -0
- package/examples/basic.ts +52 -0
- package/examples/cloudflare-workers.ts +84 -0
- package/examples/custom-handlers.ts +85 -0
- package/examples/effect/http-server.ts +205 -0
- package/examples/email-allowlist.ts +50 -0
- package/examples/express/basic.ts +26 -0
- package/examples/fastify/basic.ts +24 -0
- package/examples/hono/basic.ts +26 -0
- package/examples/hono-router.ts +74 -0
- package/examples/nestjs/basic.ts +39 -0
- package/examples/skip-dev-mode.ts +89 -0
- package/package.json +178 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { C as CloudflareAccessConfig, e as CloudflareAccessMiddlewareEnv, g as CloudflareAccessUser } from '../../jwks-ChdyyS_L.js';
|
|
2
|
+
export { A as AccessDeniedError, a as AuthRequiredError, c as CloudflareAccessError, d as CloudflareAccessErrorCode, f as CloudflareAccessPayload, h as ConfigurationError, I as InvalidTokenError, _ as __clearJwksCache, i as isAccessDeniedError, j as isAuthRequiredError, k as isCloudflareAccessError, l as isConfigurationError, m as isInvalidTokenError, t as toAuthError } from '../../jwks-ChdyyS_L.js';
|
|
3
|
+
import * as fastify from 'fastify';
|
|
4
|
+
import { FastifyReply, preHandlerHookHandler, FastifyPluginAsync } from 'fastify';
|
|
5
|
+
import 'jose';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Options for creating Cloudflare Access authentication for Fastify
|
|
9
|
+
*/
|
|
10
|
+
interface CloudflareAccessAuthOptions {
|
|
11
|
+
/** Cloudflare Access configuration */
|
|
12
|
+
accessConfig: CloudflareAccessConfig;
|
|
13
|
+
/** Optional email allowlist. Access policy should still be configured at Cloudflare. */
|
|
14
|
+
allowedEmails?: string[];
|
|
15
|
+
/** Custom unauthorized handler */
|
|
16
|
+
onUnauthorized?: (request: fastify.FastifyRequest, reply: fastify.FastifyReply, reason: string) => void | Promise<void>;
|
|
17
|
+
/** Custom forbidden handler */
|
|
18
|
+
onForbidden?: (request: fastify.FastifyRequest, reply: fastify.FastifyReply, email: string) => void | Promise<void>;
|
|
19
|
+
/** Paths to exclude from auth check */
|
|
20
|
+
excludePaths?: string[];
|
|
21
|
+
/** Whether to skip JWT validation outside production */
|
|
22
|
+
skipInDev?: boolean;
|
|
23
|
+
/** Environment indicator */
|
|
24
|
+
environment?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get Cloudflare Access configuration from environment variables
|
|
28
|
+
*/
|
|
29
|
+
declare function getCloudflareAccessConfigFromEnv(env: CloudflareAccessMiddlewareEnv): CloudflareAccessConfig;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Generate unauthorized response
|
|
33
|
+
*/
|
|
34
|
+
declare function unauthorizedResponse(reply: FastifyReply, reason: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* Generate auth required response
|
|
37
|
+
*/
|
|
38
|
+
declare function authRequiredResponse(reply: FastifyReply): void;
|
|
39
|
+
/**
|
|
40
|
+
* Generate forbidden response
|
|
41
|
+
*/
|
|
42
|
+
declare function forbiddenResponse(reply: FastifyReply): void;
|
|
43
|
+
|
|
44
|
+
declare module "fastify" {
|
|
45
|
+
interface FastifyRequest {
|
|
46
|
+
/** Authenticated user from Cloudflare Access */
|
|
47
|
+
user?: CloudflareAccessUser;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Creates a preHandler hook for Cloudflare Access authentication.
|
|
52
|
+
*
|
|
53
|
+
* @param options - Configuration options
|
|
54
|
+
* @returns Fastify preHandler hook
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* import fastify from 'fastify';
|
|
59
|
+
* import { cloudflareAccessPreHandler } from 'cloudflare-access/adapters/fastify';
|
|
60
|
+
*
|
|
61
|
+
* const app = fastify();
|
|
62
|
+
*
|
|
63
|
+
* app.addHook('preHandler', cloudflareAccessPreHandler({
|
|
64
|
+
* accessConfig: {
|
|
65
|
+
* teamDomain: 'https://yourteam.cloudflareaccess.com',
|
|
66
|
+
* audTag: 'your-audience-tag',
|
|
67
|
+
* },
|
|
68
|
+
* }));
|
|
69
|
+
*
|
|
70
|
+
* app.get('/protected', async (request, reply) => {
|
|
71
|
+
* return { email: request.user?.email };
|
|
72
|
+
* });
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
declare function cloudflareAccessPreHandler(options: CloudflareAccessAuthOptions): preHandlerHookHandler;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Creates a Fastify plugin for Cloudflare Access authentication.
|
|
79
|
+
*
|
|
80
|
+
* @param options - Configuration options
|
|
81
|
+
* @returns Fastify plugin
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* import fastify from 'fastify';
|
|
86
|
+
* import { cloudflareAccessPlugin } from 'cloudflare-access/adapters/fastify';
|
|
87
|
+
*
|
|
88
|
+
* const app = fastify();
|
|
89
|
+
*
|
|
90
|
+
* app.register(cloudflareAccessPlugin, {
|
|
91
|
+
* accessConfig: {
|
|
92
|
+
* teamDomain: 'https://yourteam.cloudflareaccess.com',
|
|
93
|
+
* audTag: 'your-audience-tag',
|
|
94
|
+
* },
|
|
95
|
+
* });
|
|
96
|
+
*
|
|
97
|
+
* app.get('/protected', async (request, reply) => {
|
|
98
|
+
* return { email: request.user?.email };
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
declare const cloudflareAccessPlugin: FastifyPluginAsync<CloudflareAccessAuthOptions>;
|
|
103
|
+
|
|
104
|
+
declare module "fastify" {
|
|
105
|
+
interface FastifyRequest {
|
|
106
|
+
/** Authenticated user from Cloudflare Access */
|
|
107
|
+
user?: CloudflareAccessUser;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export { type CloudflareAccessAuthOptions, CloudflareAccessConfig, CloudflareAccessMiddlewareEnv, CloudflareAccessUser, authRequiredResponse, cloudflareAccessPlugin, cloudflareAccessPreHandler, cloudflareAccessPlugin as default, forbiddenResponse, getCloudflareAccessConfigFromEnv, unauthorizedResponse };
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
var _chunkWUJPWM4Tjs = require('../../chunk-WUJPWM4T.js');
|
|
18
|
+
|
|
19
|
+
// src/adapters/fastify/types.ts
|
|
20
|
+
function getCloudflareAccessConfigFromEnv2(env) {
|
|
21
|
+
return _chunkWUJPWM4Tjs.getCloudflareAccessConfigFromEnv.call(void 0, env);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// src/adapters/fastify/responses.ts
|
|
25
|
+
function unauthorizedResponse(reply, reason) {
|
|
26
|
+
reply.code(401).send({
|
|
27
|
+
success: false,
|
|
28
|
+
error: {
|
|
29
|
+
code: "INVALID_TOKEN",
|
|
30
|
+
message: "Invalid authentication token",
|
|
31
|
+
why: reason,
|
|
32
|
+
fix: "Please sign in again via Cloudflare Access"
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function authRequiredResponse(reply) {
|
|
37
|
+
reply.code(401).send({
|
|
38
|
+
success: false,
|
|
39
|
+
error: {
|
|
40
|
+
code: "AUTH_REQUIRED",
|
|
41
|
+
message: "Unauthorized",
|
|
42
|
+
why: "Authentication required via Cloudflare Access",
|
|
43
|
+
fix: "Sign in via Cloudflare Access"
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function forbiddenResponse(reply) {
|
|
48
|
+
reply.code(403).send({
|
|
49
|
+
success: false,
|
|
50
|
+
error: {
|
|
51
|
+
code: "ACCESS_DENIED",
|
|
52
|
+
message: "Forbidden",
|
|
53
|
+
why: "Your email is not authorized to access this resource",
|
|
54
|
+
fix: "Contact an administrator if you need access"
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/adapters/fastify/middleware.ts
|
|
60
|
+
function cloudflareAccessPreHandler(options) {
|
|
61
|
+
const allowedEmails = _nullishCoalesce(options.allowedEmails, () => ( null));
|
|
62
|
+
return async (request, reply) => {
|
|
63
|
+
const path = request.url;
|
|
64
|
+
const method = request.method;
|
|
65
|
+
if (_optionalChain([options, 'access', _ => _.excludePaths, 'optionalAccess', _2 => _2.includes, 'call', _3 => _3(path)]) || method === "OPTIONS") {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const token = request.headers["cf-access-jwt-assertion"];
|
|
69
|
+
const protocol = request.protocol;
|
|
70
|
+
const host = request.hostname;
|
|
71
|
+
const url = `${protocol}://${host}${request.url}`;
|
|
72
|
+
const result = await _chunkWUJPWM4Tjs.validateCloudflareAccessToken.call(void 0,
|
|
73
|
+
token,
|
|
74
|
+
{
|
|
75
|
+
accessConfig: options.accessConfig,
|
|
76
|
+
allowedEmails: _nullishCoalesce(allowedEmails, () => ( void 0)),
|
|
77
|
+
skipInDev: options.skipInDev,
|
|
78
|
+
environment: options.environment
|
|
79
|
+
},
|
|
80
|
+
url
|
|
81
|
+
);
|
|
82
|
+
if (!result.success) {
|
|
83
|
+
if (_optionalChain([result, 'access', _4 => _4.error, 'optionalAccess', _5 => _5.code]) === "AUTH_REQUIRED") {
|
|
84
|
+
if (options.onUnauthorized) {
|
|
85
|
+
await options.onUnauthorized(request, reply, result.error.why);
|
|
86
|
+
} else {
|
|
87
|
+
authRequiredResponse(reply);
|
|
88
|
+
}
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (_optionalChain([result, 'access', _6 => _6.error, 'optionalAccess', _7 => _7.code]) === "ACCESS_DENIED") {
|
|
92
|
+
const email = _nullishCoalesce(_optionalChain([result, 'access', _8 => _8.user, 'optionalAccess', _9 => _9.email]), () => ( "unknown"));
|
|
93
|
+
if (options.onForbidden) {
|
|
94
|
+
await options.onForbidden(request, reply, email);
|
|
95
|
+
} else {
|
|
96
|
+
forbiddenResponse(reply);
|
|
97
|
+
}
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (options.onUnauthorized) {
|
|
101
|
+
await options.onUnauthorized(request, reply, _nullishCoalesce(_optionalChain([result, 'access', _10 => _10.error, 'optionalAccess', _11 => _11.why]), () => ( "Unknown error")));
|
|
102
|
+
} else {
|
|
103
|
+
unauthorizedResponse(reply, _nullishCoalesce(_optionalChain([result, 'access', _12 => _12.error, 'optionalAccess', _13 => _13.why]), () => ( "Unknown error")));
|
|
104
|
+
}
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (result.user) {
|
|
108
|
+
request.user = result.user;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// src/adapters/fastify/plugin.ts
|
|
114
|
+
var cloudflareAccessPlugin = async (fastify, options) => {
|
|
115
|
+
fastify.addHook("preHandler", cloudflareAccessPreHandler(options));
|
|
116
|
+
};
|
|
117
|
+
var plugin_default = cloudflareAccessPlugin;
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
exports.AccessDeniedError = _chunkWUJPWM4Tjs.AccessDeniedError; exports.AuthRequiredError = _chunkWUJPWM4Tjs.AuthRequiredError; exports.CloudflareAccessError = _chunkWUJPWM4Tjs.CloudflareAccessError; exports.CloudflareAccessErrorCode = _chunkWUJPWM4Tjs.CloudflareAccessErrorCode; exports.ConfigurationError = _chunkWUJPWM4Tjs.ConfigurationError; exports.InvalidTokenError = _chunkWUJPWM4Tjs.InvalidTokenError; exports.__clearJwksCache = _chunkWUJPWM4Tjs.__clearJwksCache; exports.authRequiredResponse = authRequiredResponse; exports.cloudflareAccessPlugin = cloudflareAccessPlugin; exports.cloudflareAccessPreHandler = cloudflareAccessPreHandler; exports.default = plugin_default; exports.forbiddenResponse = forbiddenResponse; exports.getCloudflareAccessConfigFromEnv = getCloudflareAccessConfigFromEnv2; exports.isAccessDeniedError = _chunkWUJPWM4Tjs.isAccessDeniedError; exports.isAuthRequiredError = _chunkWUJPWM4Tjs.isAuthRequiredError; exports.isCloudflareAccessError = _chunkWUJPWM4Tjs.isCloudflareAccessError; exports.isConfigurationError = _chunkWUJPWM4Tjs.isConfigurationError; exports.isInvalidTokenError = _chunkWUJPWM4Tjs.isInvalidTokenError; exports.toAuthError = _chunkWUJPWM4Tjs.toAuthError; exports.unauthorizedResponse = unauthorizedResponse;
|
|
140
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/v000281/personal/hono-cloudflare-access-middleware/dist/adapters/fastify/index.js","../../../src/adapters/fastify/types.ts","../../../src/adapters/fastify/responses.ts","../../../src/adapters/fastify/middleware.ts","../../../src/adapters/fastify/plugin.ts"],"names":["getCloudflareAccessConfigFromEnv"],"mappings":"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","file":"/Users/v000281/personal/hono-cloudflare-access-middleware/dist/adapters/fastify/index.js","sourcesContent":[null,"import type { CloudflareAccessConfig, CloudflareAccessMiddlewareEnv } from \"../../core\";\nimport { getCloudflareAccessConfigFromEnv as _getCloudflareAccessConfigFromEnv } from \"../../core\";\n\n/**\n * Options for creating Cloudflare Access authentication for Fastify\n */\nexport interface CloudflareAccessAuthOptions {\n /** Cloudflare Access configuration */\n accessConfig: CloudflareAccessConfig;\n\n /** Optional email allowlist. Access policy should still be configured at Cloudflare. */\n allowedEmails?: string[];\n\n /** Custom unauthorized handler */\n onUnauthorized?: (\n request: import(\"fastify\").FastifyRequest,\n reply: import(\"fastify\").FastifyReply,\n reason: string,\n ) => void | Promise<void>;\n\n /** Custom forbidden handler */\n onForbidden?: (\n request: import(\"fastify\").FastifyRequest,\n reply: import(\"fastify\").FastifyReply,\n email: string,\n ) => void | Promise<void>;\n\n /** Paths to exclude from auth check */\n excludePaths?: string[];\n\n /** Whether to skip JWT validation outside production */\n skipInDev?: boolean;\n\n /** Environment indicator */\n environment?: string;\n}\n\n/**\n * Get Cloudflare Access configuration from environment variables\n */\nexport function getCloudflareAccessConfigFromEnv(\n env: CloudflareAccessMiddlewareEnv,\n): CloudflareAccessConfig {\n return _getCloudflareAccessConfigFromEnv(env);\n}\n","import type { FastifyReply } from \"fastify\";\n\n/**\n * Generate unauthorized response\n */\nexport function unauthorizedResponse(reply: FastifyReply, reason: string): void {\n reply.code(401).send({\n success: false,\n error: {\n code: \"INVALID_TOKEN\",\n message: \"Invalid authentication token\",\n why: reason,\n fix: \"Please sign in again via Cloudflare Access\",\n },\n });\n}\n\n/**\n * Generate auth required response\n */\nexport function authRequiredResponse(reply: FastifyReply): void {\n reply.code(401).send({\n success: false,\n error: {\n code: \"AUTH_REQUIRED\",\n message: \"Unauthorized\",\n why: \"Authentication required via Cloudflare Access\",\n fix: \"Sign in via Cloudflare Access\",\n },\n });\n}\n\n/**\n * Generate forbidden response\n */\nexport function forbiddenResponse(reply: FastifyReply): void {\n reply.code(403).send({\n success: false,\n error: {\n code: \"ACCESS_DENIED\",\n message: \"Forbidden\",\n why: \"Your email is not authorized to access this resource\",\n fix: \"Contact an administrator if you need access\",\n },\n });\n}\n","import type { FastifyRequest, FastifyReply, FastifyInstance, preHandlerHookHandler } from \"fastify\";\nimport { validateCloudflareAccessToken } from \"../../core\";\nimport type { CloudflareAccessAuthOptions } from \"./types\";\nimport { unauthorizedResponse, authRequiredResponse, forbiddenResponse } from \"./responses\";\n\ndeclare module \"fastify\" {\n interface FastifyRequest {\n /** Authenticated user from Cloudflare Access */\n user?: import(\"../../core\").CloudflareAccessUser;\n }\n}\n\n/**\n * Creates a preHandler hook for Cloudflare Access authentication.\n *\n * @param options - Configuration options\n * @returns Fastify preHandler hook\n *\n * @example\n * ```typescript\n * import fastify from 'fastify';\n * import { cloudflareAccessPreHandler } from 'cloudflare-access/adapters/fastify';\n *\n * const app = fastify();\n *\n * app.addHook('preHandler', cloudflareAccessPreHandler({\n * accessConfig: {\n * teamDomain: 'https://yourteam.cloudflareaccess.com',\n * audTag: 'your-audience-tag',\n * },\n * }));\n *\n * app.get('/protected', async (request, reply) => {\n * return { email: request.user?.email };\n * });\n * ```\n */\nexport function cloudflareAccessPreHandler(\n options: CloudflareAccessAuthOptions,\n): preHandlerHookHandler {\n const allowedEmails = options.allowedEmails ?? null;\n\n return async (request: FastifyRequest, reply: FastifyReply): Promise<void> => {\n const path = request.url;\n const method = request.method;\n\n // Skip OPTIONS requests and excluded paths\n if (options.excludePaths?.includes(path) || method === \"OPTIONS\") {\n return;\n }\n\n const token = request.headers[\"cf-access-jwt-assertion\"] as string | undefined;\n const protocol = request.protocol;\n const host = request.hostname;\n const url = `${protocol}://${host}${request.url}`;\n\n const result = await validateCloudflareAccessToken(\n token,\n {\n accessConfig: options.accessConfig,\n allowedEmails: allowedEmails ?? undefined,\n skipInDev: options.skipInDev,\n environment: options.environment,\n },\n url,\n );\n\n if (!result.success) {\n if (result.error?.code === \"AUTH_REQUIRED\") {\n if (options.onUnauthorized) {\n await options.onUnauthorized(request, reply, result.error.why);\n } else {\n authRequiredResponse(reply);\n }\n return;\n }\n\n if (result.error?.code === \"ACCESS_DENIED\") {\n const email = result.user?.email ?? \"unknown\";\n if (options.onForbidden) {\n await options.onForbidden(request, reply, email);\n } else {\n forbiddenResponse(reply);\n }\n return;\n }\n\n if (options.onUnauthorized) {\n await options.onUnauthorized(request, reply, result.error?.why ?? \"Unknown error\");\n } else {\n unauthorizedResponse(reply, result.error?.why ?? \"Unknown error\");\n }\n return;\n }\n\n // Set user in request\n if (result.user) {\n request.user = result.user;\n }\n };\n}\n\n/**\n * Creates a Fastify plugin for Cloudflare Access authentication.\n *\n * @param options - Configuration options\n * @returns Fastify plugin\n *\n * @example\n * ```typescript\n * import fastify from 'fastify';\n * import { cloudflareAccessPlugin } from 'cloudflare-access/adapters/fastify';\n *\n * const app = fastify();\n *\n * app.register(cloudflareAccessPlugin, {\n * accessConfig: {\n * teamDomain: 'https://yourteam.cloudflareaccess.com',\n * audTag: 'your-audience-tag',\n * },\n * });\n *\n * app.get('/protected', async (request, reply) => {\n * return { email: request.user?.email };\n * });\n * ```\n */\nexport async function cloudflareAccessPlugin(\n fastify: FastifyInstance,\n options: CloudflareAccessAuthOptions,\n): Promise<void> {\n fastify.addHook(\"preHandler\", cloudflareAccessPreHandler(options));\n}\n","import type { FastifyPluginAsync } from \"fastify\";\nimport type { CloudflareAccessAuthOptions } from \"./types\";\nimport { cloudflareAccessPreHandler } from \"./middleware\";\n\n/**\n * Creates a Fastify plugin for Cloudflare Access authentication.\n *\n * @param options - Configuration options\n * @returns Fastify plugin\n *\n * @example\n * ```typescript\n * import fastify from 'fastify';\n * import { cloudflareAccessPlugin } from 'cloudflare-access/adapters/fastify';\n *\n * const app = fastify();\n *\n * app.register(cloudflareAccessPlugin, {\n * accessConfig: {\n * teamDomain: 'https://yourteam.cloudflareaccess.com',\n * audTag: 'your-audience-tag',\n * },\n * });\n *\n * app.get('/protected', async (request, reply) => {\n * return { email: request.user?.email };\n * });\n * ```\n */\nexport const cloudflareAccessPlugin: FastifyPluginAsync<CloudflareAccessAuthOptions> = async (\n fastify,\n options,\n) => {\n fastify.addHook(\"preHandler\", cloudflareAccessPreHandler(options));\n};\n\n// Also export as default for convenience\nexport default cloudflareAccessPlugin;\n"]}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AccessDeniedError,
|
|
3
|
+
AuthRequiredError,
|
|
4
|
+
CloudflareAccessError,
|
|
5
|
+
CloudflareAccessErrorCode,
|
|
6
|
+
ConfigurationError,
|
|
7
|
+
InvalidTokenError,
|
|
8
|
+
__clearJwksCache,
|
|
9
|
+
getCloudflareAccessConfigFromEnv,
|
|
10
|
+
isAccessDeniedError,
|
|
11
|
+
isAuthRequiredError,
|
|
12
|
+
isCloudflareAccessError,
|
|
13
|
+
isConfigurationError,
|
|
14
|
+
isInvalidTokenError,
|
|
15
|
+
toAuthError,
|
|
16
|
+
validateCloudflareAccessToken
|
|
17
|
+
} from "../../chunk-DM2KGIQX.mjs";
|
|
18
|
+
|
|
19
|
+
// src/adapters/fastify/types.ts
|
|
20
|
+
function getCloudflareAccessConfigFromEnv2(env) {
|
|
21
|
+
return getCloudflareAccessConfigFromEnv(env);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// src/adapters/fastify/responses.ts
|
|
25
|
+
function unauthorizedResponse(reply, reason) {
|
|
26
|
+
reply.code(401).send({
|
|
27
|
+
success: false,
|
|
28
|
+
error: {
|
|
29
|
+
code: "INVALID_TOKEN",
|
|
30
|
+
message: "Invalid authentication token",
|
|
31
|
+
why: reason,
|
|
32
|
+
fix: "Please sign in again via Cloudflare Access"
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function authRequiredResponse(reply) {
|
|
37
|
+
reply.code(401).send({
|
|
38
|
+
success: false,
|
|
39
|
+
error: {
|
|
40
|
+
code: "AUTH_REQUIRED",
|
|
41
|
+
message: "Unauthorized",
|
|
42
|
+
why: "Authentication required via Cloudflare Access",
|
|
43
|
+
fix: "Sign in via Cloudflare Access"
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function forbiddenResponse(reply) {
|
|
48
|
+
reply.code(403).send({
|
|
49
|
+
success: false,
|
|
50
|
+
error: {
|
|
51
|
+
code: "ACCESS_DENIED",
|
|
52
|
+
message: "Forbidden",
|
|
53
|
+
why: "Your email is not authorized to access this resource",
|
|
54
|
+
fix: "Contact an administrator if you need access"
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/adapters/fastify/middleware.ts
|
|
60
|
+
function cloudflareAccessPreHandler(options) {
|
|
61
|
+
const allowedEmails = options.allowedEmails ?? null;
|
|
62
|
+
return async (request, reply) => {
|
|
63
|
+
const path = request.url;
|
|
64
|
+
const method = request.method;
|
|
65
|
+
if (options.excludePaths?.includes(path) || method === "OPTIONS") {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const token = request.headers["cf-access-jwt-assertion"];
|
|
69
|
+
const protocol = request.protocol;
|
|
70
|
+
const host = request.hostname;
|
|
71
|
+
const url = `${protocol}://${host}${request.url}`;
|
|
72
|
+
const result = await validateCloudflareAccessToken(
|
|
73
|
+
token,
|
|
74
|
+
{
|
|
75
|
+
accessConfig: options.accessConfig,
|
|
76
|
+
allowedEmails: allowedEmails ?? void 0,
|
|
77
|
+
skipInDev: options.skipInDev,
|
|
78
|
+
environment: options.environment
|
|
79
|
+
},
|
|
80
|
+
url
|
|
81
|
+
);
|
|
82
|
+
if (!result.success) {
|
|
83
|
+
if (result.error?.code === "AUTH_REQUIRED") {
|
|
84
|
+
if (options.onUnauthorized) {
|
|
85
|
+
await options.onUnauthorized(request, reply, result.error.why);
|
|
86
|
+
} else {
|
|
87
|
+
authRequiredResponse(reply);
|
|
88
|
+
}
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (result.error?.code === "ACCESS_DENIED") {
|
|
92
|
+
const email = result.user?.email ?? "unknown";
|
|
93
|
+
if (options.onForbidden) {
|
|
94
|
+
await options.onForbidden(request, reply, email);
|
|
95
|
+
} else {
|
|
96
|
+
forbiddenResponse(reply);
|
|
97
|
+
}
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (options.onUnauthorized) {
|
|
101
|
+
await options.onUnauthorized(request, reply, result.error?.why ?? "Unknown error");
|
|
102
|
+
} else {
|
|
103
|
+
unauthorizedResponse(reply, result.error?.why ?? "Unknown error");
|
|
104
|
+
}
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (result.user) {
|
|
108
|
+
request.user = result.user;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// src/adapters/fastify/plugin.ts
|
|
114
|
+
var cloudflareAccessPlugin = async (fastify, options) => {
|
|
115
|
+
fastify.addHook("preHandler", cloudflareAccessPreHandler(options));
|
|
116
|
+
};
|
|
117
|
+
var plugin_default = cloudflareAccessPlugin;
|
|
118
|
+
export {
|
|
119
|
+
AccessDeniedError,
|
|
120
|
+
AuthRequiredError,
|
|
121
|
+
CloudflareAccessError,
|
|
122
|
+
CloudflareAccessErrorCode,
|
|
123
|
+
ConfigurationError,
|
|
124
|
+
InvalidTokenError,
|
|
125
|
+
__clearJwksCache,
|
|
126
|
+
authRequiredResponse,
|
|
127
|
+
cloudflareAccessPlugin,
|
|
128
|
+
cloudflareAccessPreHandler,
|
|
129
|
+
plugin_default as default,
|
|
130
|
+
forbiddenResponse,
|
|
131
|
+
getCloudflareAccessConfigFromEnv2 as getCloudflareAccessConfigFromEnv,
|
|
132
|
+
isAccessDeniedError,
|
|
133
|
+
isAuthRequiredError,
|
|
134
|
+
isCloudflareAccessError,
|
|
135
|
+
isConfigurationError,
|
|
136
|
+
isInvalidTokenError,
|
|
137
|
+
toAuthError,
|
|
138
|
+
unauthorizedResponse
|
|
139
|
+
};
|
|
140
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adapters/fastify/types.ts","../../../src/adapters/fastify/responses.ts","../../../src/adapters/fastify/middleware.ts","../../../src/adapters/fastify/plugin.ts"],"sourcesContent":["import type { CloudflareAccessConfig, CloudflareAccessMiddlewareEnv } from \"../../core\";\nimport { getCloudflareAccessConfigFromEnv as _getCloudflareAccessConfigFromEnv } from \"../../core\";\n\n/**\n * Options for creating Cloudflare Access authentication for Fastify\n */\nexport interface CloudflareAccessAuthOptions {\n /** Cloudflare Access configuration */\n accessConfig: CloudflareAccessConfig;\n\n /** Optional email allowlist. Access policy should still be configured at Cloudflare. */\n allowedEmails?: string[];\n\n /** Custom unauthorized handler */\n onUnauthorized?: (\n request: import(\"fastify\").FastifyRequest,\n reply: import(\"fastify\").FastifyReply,\n reason: string,\n ) => void | Promise<void>;\n\n /** Custom forbidden handler */\n onForbidden?: (\n request: import(\"fastify\").FastifyRequest,\n reply: import(\"fastify\").FastifyReply,\n email: string,\n ) => void | Promise<void>;\n\n /** Paths to exclude from auth check */\n excludePaths?: string[];\n\n /** Whether to skip JWT validation outside production */\n skipInDev?: boolean;\n\n /** Environment indicator */\n environment?: string;\n}\n\n/**\n * Get Cloudflare Access configuration from environment variables\n */\nexport function getCloudflareAccessConfigFromEnv(\n env: CloudflareAccessMiddlewareEnv,\n): CloudflareAccessConfig {\n return _getCloudflareAccessConfigFromEnv(env);\n}\n","import type { FastifyReply } from \"fastify\";\n\n/**\n * Generate unauthorized response\n */\nexport function unauthorizedResponse(reply: FastifyReply, reason: string): void {\n reply.code(401).send({\n success: false,\n error: {\n code: \"INVALID_TOKEN\",\n message: \"Invalid authentication token\",\n why: reason,\n fix: \"Please sign in again via Cloudflare Access\",\n },\n });\n}\n\n/**\n * Generate auth required response\n */\nexport function authRequiredResponse(reply: FastifyReply): void {\n reply.code(401).send({\n success: false,\n error: {\n code: \"AUTH_REQUIRED\",\n message: \"Unauthorized\",\n why: \"Authentication required via Cloudflare Access\",\n fix: \"Sign in via Cloudflare Access\",\n },\n });\n}\n\n/**\n * Generate forbidden response\n */\nexport function forbiddenResponse(reply: FastifyReply): void {\n reply.code(403).send({\n success: false,\n error: {\n code: \"ACCESS_DENIED\",\n message: \"Forbidden\",\n why: \"Your email is not authorized to access this resource\",\n fix: \"Contact an administrator if you need access\",\n },\n });\n}\n","import type { FastifyRequest, FastifyReply, FastifyInstance, preHandlerHookHandler } from \"fastify\";\nimport { validateCloudflareAccessToken } from \"../../core\";\nimport type { CloudflareAccessAuthOptions } from \"./types\";\nimport { unauthorizedResponse, authRequiredResponse, forbiddenResponse } from \"./responses\";\n\ndeclare module \"fastify\" {\n interface FastifyRequest {\n /** Authenticated user from Cloudflare Access */\n user?: import(\"../../core\").CloudflareAccessUser;\n }\n}\n\n/**\n * Creates a preHandler hook for Cloudflare Access authentication.\n *\n * @param options - Configuration options\n * @returns Fastify preHandler hook\n *\n * @example\n * ```typescript\n * import fastify from 'fastify';\n * import { cloudflareAccessPreHandler } from 'cloudflare-access/adapters/fastify';\n *\n * const app = fastify();\n *\n * app.addHook('preHandler', cloudflareAccessPreHandler({\n * accessConfig: {\n * teamDomain: 'https://yourteam.cloudflareaccess.com',\n * audTag: 'your-audience-tag',\n * },\n * }));\n *\n * app.get('/protected', async (request, reply) => {\n * return { email: request.user?.email };\n * });\n * ```\n */\nexport function cloudflareAccessPreHandler(\n options: CloudflareAccessAuthOptions,\n): preHandlerHookHandler {\n const allowedEmails = options.allowedEmails ?? null;\n\n return async (request: FastifyRequest, reply: FastifyReply): Promise<void> => {\n const path = request.url;\n const method = request.method;\n\n // Skip OPTIONS requests and excluded paths\n if (options.excludePaths?.includes(path) || method === \"OPTIONS\") {\n return;\n }\n\n const token = request.headers[\"cf-access-jwt-assertion\"] as string | undefined;\n const protocol = request.protocol;\n const host = request.hostname;\n const url = `${protocol}://${host}${request.url}`;\n\n const result = await validateCloudflareAccessToken(\n token,\n {\n accessConfig: options.accessConfig,\n allowedEmails: allowedEmails ?? undefined,\n skipInDev: options.skipInDev,\n environment: options.environment,\n },\n url,\n );\n\n if (!result.success) {\n if (result.error?.code === \"AUTH_REQUIRED\") {\n if (options.onUnauthorized) {\n await options.onUnauthorized(request, reply, result.error.why);\n } else {\n authRequiredResponse(reply);\n }\n return;\n }\n\n if (result.error?.code === \"ACCESS_DENIED\") {\n const email = result.user?.email ?? \"unknown\";\n if (options.onForbidden) {\n await options.onForbidden(request, reply, email);\n } else {\n forbiddenResponse(reply);\n }\n return;\n }\n\n if (options.onUnauthorized) {\n await options.onUnauthorized(request, reply, result.error?.why ?? \"Unknown error\");\n } else {\n unauthorizedResponse(reply, result.error?.why ?? \"Unknown error\");\n }\n return;\n }\n\n // Set user in request\n if (result.user) {\n request.user = result.user;\n }\n };\n}\n\n/**\n * Creates a Fastify plugin for Cloudflare Access authentication.\n *\n * @param options - Configuration options\n * @returns Fastify plugin\n *\n * @example\n * ```typescript\n * import fastify from 'fastify';\n * import { cloudflareAccessPlugin } from 'cloudflare-access/adapters/fastify';\n *\n * const app = fastify();\n *\n * app.register(cloudflareAccessPlugin, {\n * accessConfig: {\n * teamDomain: 'https://yourteam.cloudflareaccess.com',\n * audTag: 'your-audience-tag',\n * },\n * });\n *\n * app.get('/protected', async (request, reply) => {\n * return { email: request.user?.email };\n * });\n * ```\n */\nexport async function cloudflareAccessPlugin(\n fastify: FastifyInstance,\n options: CloudflareAccessAuthOptions,\n): Promise<void> {\n fastify.addHook(\"preHandler\", cloudflareAccessPreHandler(options));\n}\n","import type { FastifyPluginAsync } from \"fastify\";\nimport type { CloudflareAccessAuthOptions } from \"./types\";\nimport { cloudflareAccessPreHandler } from \"./middleware\";\n\n/**\n * Creates a Fastify plugin for Cloudflare Access authentication.\n *\n * @param options - Configuration options\n * @returns Fastify plugin\n *\n * @example\n * ```typescript\n * import fastify from 'fastify';\n * import { cloudflareAccessPlugin } from 'cloudflare-access/adapters/fastify';\n *\n * const app = fastify();\n *\n * app.register(cloudflareAccessPlugin, {\n * accessConfig: {\n * teamDomain: 'https://yourteam.cloudflareaccess.com',\n * audTag: 'your-audience-tag',\n * },\n * });\n *\n * app.get('/protected', async (request, reply) => {\n * return { email: request.user?.email };\n * });\n * ```\n */\nexport const cloudflareAccessPlugin: FastifyPluginAsync<CloudflareAccessAuthOptions> = async (\n fastify,\n options,\n) => {\n fastify.addHook(\"preHandler\", cloudflareAccessPreHandler(options));\n};\n\n// Also export as default for convenience\nexport default cloudflareAccessPlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwCO,SAASA,kCACd,KACwB;AACxB,SAAO,iCAAkC,GAAG;AAC9C;;;ACvCO,SAAS,qBAAqB,OAAqB,QAAsB;AAC9E,QAAM,KAAK,GAAG,EAAE,KAAK;AAAA,IACnB,SAAS;AAAA,IACT,OAAO;AAAA,MACL,MAAM;AAAA,MACN,SAAS;AAAA,MACT,KAAK;AAAA,MACL,KAAK;AAAA,IACP;AAAA,EACF,CAAC;AACH;AAKO,SAAS,qBAAqB,OAA2B;AAC9D,QAAM,KAAK,GAAG,EAAE,KAAK;AAAA,IACnB,SAAS;AAAA,IACT,OAAO;AAAA,MACL,MAAM;AAAA,MACN,SAAS;AAAA,MACT,KAAK;AAAA,MACL,KAAK;AAAA,IACP;AAAA,EACF,CAAC;AACH;AAKO,SAAS,kBAAkB,OAA2B;AAC3D,QAAM,KAAK,GAAG,EAAE,KAAK;AAAA,IACnB,SAAS;AAAA,IACT,OAAO;AAAA,MACL,MAAM;AAAA,MACN,SAAS;AAAA,MACT,KAAK;AAAA,MACL,KAAK;AAAA,IACP;AAAA,EACF,CAAC;AACH;;;ACRO,SAAS,2BACd,SACuB;AACvB,QAAM,gBAAgB,QAAQ,iBAAiB;AAE/C,SAAO,OAAO,SAAyB,UAAuC;AAC5E,UAAM,OAAO,QAAQ;AACrB,UAAM,SAAS,QAAQ;AAGvB,QAAI,QAAQ,cAAc,SAAS,IAAI,KAAK,WAAW,WAAW;AAChE;AAAA,IACF;AAEA,UAAM,QAAQ,QAAQ,QAAQ,yBAAyB;AACvD,UAAM,WAAW,QAAQ;AACzB,UAAM,OAAO,QAAQ;AACrB,UAAM,MAAM,GAAG,QAAQ,MAAM,IAAI,GAAG,QAAQ,GAAG;AAE/C,UAAM,SAAS,MAAM;AAAA,MACnB;AAAA,MACA;AAAA,QACE,cAAc,QAAQ;AAAA,QACtB,eAAe,iBAAiB;AAAA,QAChC,WAAW,QAAQ;AAAA,QACnB,aAAa,QAAQ;AAAA,MACvB;AAAA,MACA;AAAA,IACF;AAEA,QAAI,CAAC,OAAO,SAAS;AACnB,UAAI,OAAO,OAAO,SAAS,iBAAiB;AAC1C,YAAI,QAAQ,gBAAgB;AAC1B,gBAAM,QAAQ,eAAe,SAAS,OAAO,OAAO,MAAM,GAAG;AAAA,QAC/D,OAAO;AACL,+BAAqB,KAAK;AAAA,QAC5B;AACA;AAAA,MACF;AAEA,UAAI,OAAO,OAAO,SAAS,iBAAiB;AAC1C,cAAM,QAAQ,OAAO,MAAM,SAAS;AACpC,YAAI,QAAQ,aAAa;AACvB,gBAAM,QAAQ,YAAY,SAAS,OAAO,KAAK;AAAA,QACjD,OAAO;AACL,4BAAkB,KAAK;AAAA,QACzB;AACA;AAAA,MACF;AAEA,UAAI,QAAQ,gBAAgB;AAC1B,cAAM,QAAQ,eAAe,SAAS,OAAO,OAAO,OAAO,OAAO,eAAe;AAAA,MACnF,OAAO;AACL,6BAAqB,OAAO,OAAO,OAAO,OAAO,eAAe;AAAA,MAClE;AACA;AAAA,IACF;AAGA,QAAI,OAAO,MAAM;AACf,cAAQ,OAAO,OAAO;AAAA,IACxB;AAAA,EACF;AACF;;;ACvEO,IAAM,yBAA0E,OACrF,SACA,YACG;AACH,UAAQ,QAAQ,cAAc,2BAA2B,OAAO,CAAC;AACnE;AAGA,IAAO,iBAAQ;","names":["getCloudflareAccessConfigFromEnv"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { A as AccessDeniedError, a as AuthRequiredError, C as CloudflareAccessConfig, c as CloudflareAccessError, d as CloudflareAccessErrorCode, e as CloudflareAccessMiddlewareEnv, f as CloudflareAccessPayload, g as CloudflareAccessUser, h as ConfigurationError, I as InvalidTokenError, _ as __clearJwksCache, i as isAccessDeniedError, j as isAuthRequiredError, k as isCloudflareAccessError, l as isConfigurationError, m as isInvalidTokenError, t as toAuthError } from '../../jwks-ChdyyS_L.mjs';
|
|
2
|
+
export { C as CloudflareAccessAuthOptions, a as CloudflareAccessConfigResolver, b as CloudflareAccessHono, c as CloudflareAccessVariables, d as createCloudflareAccessAuth, g as getCloudflareAccessConfigFromBindings, r as resolveConfig } from '../../middleware-BDl6jUCu.mjs';
|
|
3
|
+
import { Context } from 'hono';
|
|
4
|
+
import 'jose';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Generate unauthorized response
|
|
8
|
+
*/
|
|
9
|
+
declare function unauthorizedResponse(c: Context, reason: string): Response;
|
|
10
|
+
/**
|
|
11
|
+
* Generate auth required response
|
|
12
|
+
*/
|
|
13
|
+
declare function authRequiredResponse(c: Context): Response;
|
|
14
|
+
/**
|
|
15
|
+
* Generate forbidden response
|
|
16
|
+
*/
|
|
17
|
+
declare function forbiddenResponse(c: Context): Response;
|
|
18
|
+
|
|
19
|
+
export { authRequiredResponse, forbiddenResponse, unauthorizedResponse };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { A as AccessDeniedError, a as AuthRequiredError, C as CloudflareAccessConfig, c as CloudflareAccessError, d as CloudflareAccessErrorCode, e as CloudflareAccessMiddlewareEnv, f as CloudflareAccessPayload, g as CloudflareAccessUser, h as ConfigurationError, I as InvalidTokenError, _ as __clearJwksCache, i as isAccessDeniedError, j as isAuthRequiredError, k as isCloudflareAccessError, l as isConfigurationError, m as isInvalidTokenError, t as toAuthError } from '../../jwks-ChdyyS_L.js';
|
|
2
|
+
export { C as CloudflareAccessAuthOptions, a as CloudflareAccessConfigResolver, b as CloudflareAccessHono, c as CloudflareAccessVariables, d as createCloudflareAccessAuth, g as getCloudflareAccessConfigFromBindings, r as resolveConfig } from '../../middleware-CgFsjM20.js';
|
|
3
|
+
import { Context } from 'hono';
|
|
4
|
+
import 'jose';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Generate unauthorized response
|
|
8
|
+
*/
|
|
9
|
+
declare function unauthorizedResponse(c: Context, reason: string): Response;
|
|
10
|
+
/**
|
|
11
|
+
* Generate auth required response
|
|
12
|
+
*/
|
|
13
|
+
declare function authRequiredResponse(c: Context): Response;
|
|
14
|
+
/**
|
|
15
|
+
* Generate forbidden response
|
|
16
|
+
*/
|
|
17
|
+
declare function forbiddenResponse(c: Context): Response;
|
|
18
|
+
|
|
19
|
+
export { authRequiredResponse, forbiddenResponse, unauthorizedResponse };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunkPMFPT3SIjs = require('../../chunk-PMFPT3SI.js');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
var _chunkWUJPWM4Tjs = require('../../chunk-WUJPWM4T.js');
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
exports.AccessDeniedError = _chunkWUJPWM4Tjs.AccessDeniedError; exports.AuthRequiredError = _chunkWUJPWM4Tjs.AuthRequiredError; exports.CloudflareAccessError = _chunkWUJPWM4Tjs.CloudflareAccessError; exports.CloudflareAccessErrorCode = _chunkWUJPWM4Tjs.CloudflareAccessErrorCode; exports.ConfigurationError = _chunkWUJPWM4Tjs.ConfigurationError; exports.InvalidTokenError = _chunkWUJPWM4Tjs.InvalidTokenError; exports.__clearJwksCache = _chunkWUJPWM4Tjs.__clearJwksCache; exports.authRequiredResponse = _chunkPMFPT3SIjs.authRequiredResponse; exports.createCloudflareAccessAuth = _chunkPMFPT3SIjs.createCloudflareAccessAuth; exports.forbiddenResponse = _chunkPMFPT3SIjs.forbiddenResponse; exports.getCloudflareAccessConfigFromBindings = _chunkPMFPT3SIjs.getCloudflareAccessConfigFromBindings; exports.isAccessDeniedError = _chunkWUJPWM4Tjs.isAccessDeniedError; exports.isAuthRequiredError = _chunkWUJPWM4Tjs.isAuthRequiredError; exports.isCloudflareAccessError = _chunkWUJPWM4Tjs.isCloudflareAccessError; exports.isConfigurationError = _chunkWUJPWM4Tjs.isConfigurationError; exports.isInvalidTokenError = _chunkWUJPWM4Tjs.isInvalidTokenError; exports.resolveConfig = _chunkPMFPT3SIjs.resolveConfig; exports.toAuthError = _chunkWUJPWM4Tjs.toAuthError; exports.unauthorizedResponse = _chunkPMFPT3SIjs.unauthorizedResponse;
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/v000281/personal/hono-cloudflare-access-middleware/dist/adapters/hono/index.js"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACF,0DAAgC;AAChC;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,0DAAgC;AAChC;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,uyCAAC","file":"/Users/v000281/personal/hono-cloudflare-access-middleware/dist/adapters/hono/index.js"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
authRequiredResponse,
|
|
3
|
+
createCloudflareAccessAuth,
|
|
4
|
+
forbiddenResponse,
|
|
5
|
+
getCloudflareAccessConfigFromBindings,
|
|
6
|
+
resolveConfig,
|
|
7
|
+
unauthorizedResponse
|
|
8
|
+
} from "../../chunk-LQWCGHLJ.mjs";
|
|
9
|
+
import {
|
|
10
|
+
AccessDeniedError,
|
|
11
|
+
AuthRequiredError,
|
|
12
|
+
CloudflareAccessError,
|
|
13
|
+
CloudflareAccessErrorCode,
|
|
14
|
+
ConfigurationError,
|
|
15
|
+
InvalidTokenError,
|
|
16
|
+
__clearJwksCache,
|
|
17
|
+
isAccessDeniedError,
|
|
18
|
+
isAuthRequiredError,
|
|
19
|
+
isCloudflareAccessError,
|
|
20
|
+
isConfigurationError,
|
|
21
|
+
isInvalidTokenError,
|
|
22
|
+
toAuthError
|
|
23
|
+
} from "../../chunk-DM2KGIQX.mjs";
|
|
24
|
+
export {
|
|
25
|
+
AccessDeniedError,
|
|
26
|
+
AuthRequiredError,
|
|
27
|
+
CloudflareAccessError,
|
|
28
|
+
CloudflareAccessErrorCode,
|
|
29
|
+
ConfigurationError,
|
|
30
|
+
InvalidTokenError,
|
|
31
|
+
__clearJwksCache,
|
|
32
|
+
authRequiredResponse,
|
|
33
|
+
createCloudflareAccessAuth,
|
|
34
|
+
forbiddenResponse,
|
|
35
|
+
getCloudflareAccessConfigFromBindings,
|
|
36
|
+
isAccessDeniedError,
|
|
37
|
+
isAuthRequiredError,
|
|
38
|
+
isCloudflareAccessError,
|
|
39
|
+
isConfigurationError,
|
|
40
|
+
isInvalidTokenError,
|
|
41
|
+
resolveConfig,
|
|
42
|
+
toAuthError,
|
|
43
|
+
unauthorizedResponse
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|