actor-gate 0.1.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/package.json +25 -0
- package/src/config/base-config.d.ts +17 -0
- package/src/config/base-config.js +33 -0
- package/src/config/index.d.ts +5 -0
- package/src/config/index.js +5 -0
- package/src/config/nextjs-public-config.d.ts +46 -0
- package/src/config/nextjs-public-config.js +89 -0
- package/src/config/nextjs-server-config.d.ts +32 -0
- package/src/config/nextjs-server-config.js +10 -0
- package/src/config/react-client.d.ts +23 -0
- package/src/config/react-client.js +69 -0
- package/src/config/react-config.d.ts +18 -0
- package/src/config/react-config.js +38 -0
- package/src/core/adapters/access-token-revocation-adapter.d.ts +8 -0
- package/src/core/adapters/access-token-revocation-adapter.js +1 -0
- package/src/core/adapters/access-token-transport-adapter.d.ts +15 -0
- package/src/core/adapters/access-token-transport-adapter.js +1 -0
- package/src/core/adapters/authorization-code-adapter.d.ts +21 -0
- package/src/core/adapters/authorization-code-adapter.js +1 -0
- package/src/core/adapters/authorization-hooks.d.ts +13 -0
- package/src/core/adapters/authorization-hooks.js +1 -0
- package/src/core/adapters/index.d.ts +14 -0
- package/src/core/adapters/index.js +1 -0
- package/src/core/adapters/login-method-adapter.d.ts +7 -0
- package/src/core/adapters/login-method-adapter.js +1 -0
- package/src/core/adapters/oauth-client-adapter.d.ts +13 -0
- package/src/core/adapters/oauth-client-adapter.js +1 -0
- package/src/core/adapters/oauth-client-management-adapter.d.ts +23 -0
- package/src/core/adapters/oauth-client-management-adapter.js +1 -0
- package/src/core/adapters/oauth-grant-type.d.ts +1 -0
- package/src/core/adapters/oauth-grant-type.js +1 -0
- package/src/core/adapters/oauth-policy.d.ts +9 -0
- package/src/core/adapters/oauth-policy.js +1 -0
- package/src/core/adapters/observability-hooks.d.ts +31 -0
- package/src/core/adapters/observability-hooks.js +1 -0
- package/src/core/adapters/pending-auth-request-adapter.d.ts +18 -0
- package/src/core/adapters/pending-auth-request-adapter.js +1 -0
- package/src/core/adapters/refresh-token-adapter.d.ts +24 -0
- package/src/core/adapters/refresh-token-adapter.js +1 -0
- package/src/core/adapters/session-adapter.d.ts +14 -0
- package/src/core/adapters/session-adapter.js +1 -0
- package/src/core/adapters/token-adapter.d.ts +15 -0
- package/src/core/adapters/token-adapter.js +1 -0
- package/src/core/http/bearer-challenge.d.ts +6 -0
- package/src/core/http/bearer-challenge.js +16 -0
- package/src/core/ids/id-codec.d.ts +6 -0
- package/src/core/ids/id-codec.js +30 -0
- package/src/core/index.d.ts +9 -0
- package/src/core/index.js +7 -0
- package/src/core/oauth/pkce.d.ts +9 -0
- package/src/core/oauth/pkce.js +30 -0
- package/src/core/services/access-token-service.d.ts +42 -0
- package/src/core/services/access-token-service.js +304 -0
- package/src/core/services/auth-error.d.ts +14 -0
- package/src/core/services/auth-error.js +47 -0
- package/src/core/services/contracts.d.ts +23 -0
- package/src/core/services/contracts.js +1 -0
- package/src/core/services/direct-auth-service.d.ts +50 -0
- package/src/core/services/direct-auth-service.js +267 -0
- package/src/core/services/index.d.ts +7 -0
- package/src/core/services/index.js +5 -0
- package/src/core/services/mcp-auth-service.d.ts +39 -0
- package/src/core/services/mcp-auth-service.js +170 -0
- package/src/core/services/oauth-service.d.ts +91 -0
- package/src/core/services/oauth-service.js +571 -0
- package/src/core/services/observability.d.ts +22 -0
- package/src/core/services/observability.js +71 -0
- package/src/core/services/revocation-policy.d.ts +21 -0
- package/src/core/services/revocation-policy.js +51 -0
- package/src/core/sessions/client-session.d.ts +7 -0
- package/src/core/sessions/client-session.js +18 -0
- package/src/core/tokens/access-claims.d.ts +21 -0
- package/src/core/tokens/access-claims.js +128 -0
- package/src/core/tokens/id-claims.d.ts +20 -0
- package/src/core/tokens/id-claims.js +25 -0
- package/src/core/types/auth-contract.d.ts +33 -0
- package/src/core/types/auth-contract.js +1 -0
- package/src/express/index.d.ts +1 -0
- package/src/express/index.js +1 -0
- package/src/express/protected-route.d.ts +44 -0
- package/src/express/protected-route.js +119 -0
- package/src/index.d.ts +8 -0
- package/src/index.js +8 -0
- package/src/mcp/index.d.ts +1 -0
- package/src/mcp/index.js +1 -0
- package/src/mcp/json-rpc-auth.d.ts +5 -0
- package/src/mcp/json-rpc-auth.js +41 -0
- package/src/next/app/catch-all.d.ts +32 -0
- package/src/next/app/catch-all.js +82 -0
- package/src/next/app/cookies.d.ts +22 -0
- package/src/next/app/cookies.js +36 -0
- package/src/next/app/direct-auth-handlers.d.ts +55 -0
- package/src/next/app/direct-auth-handlers.js +419 -0
- package/src/next/app/index.d.ts +8 -0
- package/src/next/app/index.js +8 -0
- package/src/next/app/mcp-oauth-handlers.d.ts +74 -0
- package/src/next/app/mcp-oauth-handlers.js +365 -0
- package/src/next/app/protected-route.d.ts +27 -0
- package/src/next/app/protected-route.js +59 -0
- package/src/next/app/request.d.ts +12 -0
- package/src/next/app/request.js +30 -0
- package/src/next/app/response.d.ts +16 -0
- package/src/next/app/response.js +48 -0
- package/src/next/app/wrapper.d.ts +28 -0
- package/src/next/app/wrapper.js +78 -0
- package/src/next/index.d.ts +6 -0
- package/src/next/index.js +5 -0
- package/src/next/pages/catch-all.d.ts +19 -0
- package/src/next/pages/catch-all.js +60 -0
- package/src/next/pages/cookies.d.ts +41 -0
- package/src/next/pages/cookies.js +87 -0
- package/src/next/pages/direct-auth-handlers.d.ts +58 -0
- package/src/next/pages/direct-auth-handlers.js +425 -0
- package/src/next/pages/index.d.ts +8 -0
- package/src/next/pages/index.js +8 -0
- package/src/next/pages/mcp-oauth-handlers.d.ts +77 -0
- package/src/next/pages/mcp-oauth-handlers.js +341 -0
- package/src/next/pages/protected-route.d.ts +28 -0
- package/src/next/pages/protected-route.js +59 -0
- package/src/next/pages/request.d.ts +14 -0
- package/src/next/pages/request.js +66 -0
- package/src/next/pages/response.d.ts +28 -0
- package/src/next/pages/response.js +29 -0
- package/src/next/pages/wrapper.d.ts +29 -0
- package/src/next/pages/wrapper.js +74 -0
- package/src/next/rewrites.d.ts +12 -0
- package/src/next/rewrites.js +74 -0
- package/src/next/shared/auth-http.d.ts +24 -0
- package/src/next/shared/auth-http.js +42 -0
- package/src/next/shared/auth-routes.d.ts +17 -0
- package/src/next/shared/auth-routes.js +153 -0
- package/src/next/shared/direct-auth-utils.d.ts +71 -0
- package/src/next/shared/direct-auth-utils.js +275 -0
- package/src/next/shared/oauth-utils.d.ts +45 -0
- package/src/next/shared/oauth-utils.js +308 -0
- package/src/next/shared/well-known-utils.d.ts +46 -0
- package/src/next/shared/well-known-utils.js +108 -0
- package/src/testing/in-memory/in-memory-access-token-revocation-adapter.d.ts +2 -0
- package/src/testing/in-memory/in-memory-access-token-revocation-adapter.js +14 -0
- package/src/testing/in-memory/in-memory-authorization-code-adapter.d.ts +2 -0
- package/src/testing/in-memory/in-memory-authorization-code-adapter.js +36 -0
- package/src/testing/in-memory/in-memory-oauth-client-adapter.d.ts +14 -0
- package/src/testing/in-memory/in-memory-oauth-client-adapter.js +26 -0
- package/src/testing/in-memory/in-memory-pending-auth-request-adapter.d.ts +2 -0
- package/src/testing/in-memory/in-memory-pending-auth-request-adapter.js +43 -0
- package/src/testing/in-memory/in-memory-refresh-token-adapter.d.ts +2 -0
- package/src/testing/in-memory/in-memory-refresh-token-adapter.js +67 -0
- package/src/testing/in-memory/in-memory-session-adapter.d.ts +6 -0
- package/src/testing/in-memory/in-memory-session-adapter.js +43 -0
- package/src/testing/in-memory/index.d.ts +7 -0
- package/src/testing/in-memory/index.js +7 -0
- package/src/testing/in-memory/test-fixtures.d.ts +5 -0
- package/src/testing/in-memory/test-fixtures.js +18 -0
- package/src/testing/index.d.ts +2 -0
- package/src/testing/index.js +4 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { isAuthServiceError } from '../../core/services/auth-error';
|
|
2
|
+
import { buildAppAccessTokenTransportInput, getAppCookies, getAppRequestId, } from './request';
|
|
3
|
+
import { sendAppAuthError, sendAppSystemError } from './response';
|
|
4
|
+
export function withAppAuthRoute(options) {
|
|
5
|
+
return async function appAuthRoute(req) {
|
|
6
|
+
const requestId = getAppRequestId(req, options.requestIdHeaderName);
|
|
7
|
+
const transport = buildAppAccessTokenTransportInput({
|
|
8
|
+
req,
|
|
9
|
+
...(options.authorizationHeaderName === undefined
|
|
10
|
+
? {}
|
|
11
|
+
: { authorizationHeaderName: options.authorizationHeaderName }),
|
|
12
|
+
});
|
|
13
|
+
const cookies = getAppCookies(req);
|
|
14
|
+
try {
|
|
15
|
+
const output = await options.handler({
|
|
16
|
+
req,
|
|
17
|
+
...(requestId === undefined ? {} : { requestId }),
|
|
18
|
+
transport,
|
|
19
|
+
cookies,
|
|
20
|
+
});
|
|
21
|
+
if (output instanceof Response) {
|
|
22
|
+
return output;
|
|
23
|
+
}
|
|
24
|
+
if (output === undefined) {
|
|
25
|
+
return new Response(null, { status: 204 });
|
|
26
|
+
}
|
|
27
|
+
if (options.send) {
|
|
28
|
+
return options.send({
|
|
29
|
+
req,
|
|
30
|
+
output,
|
|
31
|
+
...(requestId === undefined ? {} : { requestId }),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return new Response(JSON.stringify(output), {
|
|
35
|
+
status: 200,
|
|
36
|
+
headers: {
|
|
37
|
+
'Content-Type': 'application/json',
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (isAuthServiceError(error)) {
|
|
43
|
+
return sendAppAuthError(error, {
|
|
44
|
+
...(requestId === undefined ? {} : { requestId }),
|
|
45
|
+
...(options.challenge?.scope === undefined
|
|
46
|
+
? {}
|
|
47
|
+
: { challengeScope: options.challenge.scope }),
|
|
48
|
+
...(options.challenge?.resourceMetadataUrl === undefined
|
|
49
|
+
? {}
|
|
50
|
+
: { resourceMetadataUrl: options.challenge.resourceMetadataUrl }),
|
|
51
|
+
...(options.challenge?.includeErrorInWwwAuthenticate === undefined
|
|
52
|
+
? {}
|
|
53
|
+
: {
|
|
54
|
+
includeChallengeError: options.challenge.includeErrorInWwwAuthenticate,
|
|
55
|
+
}),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if (options.onSystemError) {
|
|
59
|
+
try {
|
|
60
|
+
const hooked = await options.onSystemError({
|
|
61
|
+
req,
|
|
62
|
+
error,
|
|
63
|
+
...(requestId === undefined ? {} : { requestId }),
|
|
64
|
+
});
|
|
65
|
+
if (hooked instanceof Response) {
|
|
66
|
+
return hooked;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
// Wrapper never throws from system-error hooks.
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return sendAppSystemError({
|
|
74
|
+
...(requestId === undefined ? {} : { requestId }),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const SUPPORTED_NEXT_ROUTERS: readonly ["pages", "app"];
|
|
2
|
+
export type SupportedNextRouter = (typeof SUPPORTED_NEXT_ROUTERS)[number];
|
|
3
|
+
export * from './pages/index';
|
|
4
|
+
export * from './app/index';
|
|
5
|
+
export * from './shared/auth-routes';
|
|
6
|
+
export * from './rewrites';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { NextApiHandler, NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
+
import { type AuthRouteAction, type AuthRouteHttpMethod } from '../shared/auth-routes';
|
|
3
|
+
export type PagesAuthCatchAllHandler = (req: NextApiRequest, res: NextApiResponse) => Promise<void> | void;
|
|
4
|
+
export type CreatePagesAuthCatchAllHandlerOptions = {
|
|
5
|
+
handlers: Partial<Record<AuthRouteAction, PagesAuthCatchAllHandler>>;
|
|
6
|
+
onUnsupportedRoute?: (input: {
|
|
7
|
+
req: NextApiRequest;
|
|
8
|
+
res: NextApiResponse;
|
|
9
|
+
segments: readonly string[];
|
|
10
|
+
action?: AuthRouteAction;
|
|
11
|
+
}) => Promise<void> | void;
|
|
12
|
+
onMethodNotAllowed?: (input: {
|
|
13
|
+
req: NextApiRequest;
|
|
14
|
+
res: NextApiResponse;
|
|
15
|
+
action: AuthRouteAction;
|
|
16
|
+
allowedMethods: readonly AuthRouteHttpMethod[];
|
|
17
|
+
}) => Promise<void> | void;
|
|
18
|
+
};
|
|
19
|
+
export declare function createPagesAuthCatchAllHandler(options: CreatePagesAuthCatchAllHandlerOptions): NextApiHandler;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { isAuthRouteMethodAllowed, normalizeAuthRouteSegments, resolveAuthRoute, } from '../shared/auth-routes';
|
|
2
|
+
function sendUnsupportedRoute(res) {
|
|
3
|
+
res.status(404).json({
|
|
4
|
+
error: 'not_found',
|
|
5
|
+
error_description: 'Unsupported auth route.',
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
function sendMethodNotAllowed(res, allowedMethods) {
|
|
9
|
+
res.setHeader('Allow', allowedMethods.join(', '));
|
|
10
|
+
res.status(405).json({
|
|
11
|
+
error: 'method_not_allowed',
|
|
12
|
+
error_description: 'HTTP method not allowed for auth route.',
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
export function createPagesAuthCatchAllHandler(options) {
|
|
16
|
+
return async function pagesAuthCatchAll(req, res) {
|
|
17
|
+
const segments = normalizeAuthRouteSegments(req.query.auth);
|
|
18
|
+
const route = resolveAuthRoute(segments);
|
|
19
|
+
if (!route) {
|
|
20
|
+
if (options.onUnsupportedRoute) {
|
|
21
|
+
await options.onUnsupportedRoute({
|
|
22
|
+
req,
|
|
23
|
+
res,
|
|
24
|
+
segments,
|
|
25
|
+
});
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
sendUnsupportedRoute(res);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (!isAuthRouteMethodAllowed(route, req.method)) {
|
|
32
|
+
if (options.onMethodNotAllowed) {
|
|
33
|
+
await options.onMethodNotAllowed({
|
|
34
|
+
req,
|
|
35
|
+
res,
|
|
36
|
+
action: route.action,
|
|
37
|
+
allowedMethods: route.methods,
|
|
38
|
+
});
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
sendMethodNotAllowed(res, route.methods);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const handler = options.handlers[route.action];
|
|
45
|
+
if (!handler) {
|
|
46
|
+
if (options.onUnsupportedRoute) {
|
|
47
|
+
await options.onUnsupportedRoute({
|
|
48
|
+
req,
|
|
49
|
+
res,
|
|
50
|
+
segments,
|
|
51
|
+
action: route.action,
|
|
52
|
+
});
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
sendUnsupportedRoute(res);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
await handler(req, res);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export type CookieSameSite = 'lax' | 'strict' | 'none';
|
|
2
|
+
type SetCookieHeaderValue = string | number | readonly string[] | undefined;
|
|
3
|
+
type SetCookieHeaderResponse = {
|
|
4
|
+
getHeader(name: 'Set-Cookie'): SetCookieHeaderValue;
|
|
5
|
+
setHeader(name: 'Set-Cookie', value: string | string[]): void;
|
|
6
|
+
};
|
|
7
|
+
export type PagesCookieOptions = {
|
|
8
|
+
path?: string;
|
|
9
|
+
domain?: string;
|
|
10
|
+
maxAgeSeconds?: number;
|
|
11
|
+
expires?: Date;
|
|
12
|
+
secure?: boolean;
|
|
13
|
+
httpOnly?: boolean;
|
|
14
|
+
sameSite?: CookieSameSite;
|
|
15
|
+
};
|
|
16
|
+
export declare function serializeSetCookie(input: {
|
|
17
|
+
name: string;
|
|
18
|
+
value: string;
|
|
19
|
+
options?: PagesCookieOptions;
|
|
20
|
+
}): string;
|
|
21
|
+
export declare function appendSetCookieHeader(res: SetCookieHeaderResponse, serializedCookie: string): void;
|
|
22
|
+
export declare function setPagesCookie(res: SetCookieHeaderResponse, input: {
|
|
23
|
+
name: string;
|
|
24
|
+
value: string;
|
|
25
|
+
options?: PagesCookieOptions;
|
|
26
|
+
}): string;
|
|
27
|
+
export declare function setPagesAuthCookie(res: SetCookieHeaderResponse, input: {
|
|
28
|
+
name: string;
|
|
29
|
+
value: string;
|
|
30
|
+
maxAgeSeconds: number;
|
|
31
|
+
secure?: boolean;
|
|
32
|
+
sameSite?: CookieSameSite;
|
|
33
|
+
path?: string;
|
|
34
|
+
}): string;
|
|
35
|
+
export declare function clearPagesAuthCookie(res: SetCookieHeaderResponse, input: {
|
|
36
|
+
name: string;
|
|
37
|
+
secure?: boolean;
|
|
38
|
+
sameSite?: CookieSameSite;
|
|
39
|
+
path?: string;
|
|
40
|
+
}): string;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
export function serializeSetCookie(input) {
|
|
2
|
+
if (input.name.length === 0) {
|
|
3
|
+
throw new Error('Cookie name must be a non-empty string.');
|
|
4
|
+
}
|
|
5
|
+
const options = input.options ?? {};
|
|
6
|
+
if (options.maxAgeSeconds !== undefined &&
|
|
7
|
+
(!Number.isSafeInteger(options.maxAgeSeconds) || options.maxAgeSeconds < 0)) {
|
|
8
|
+
throw new Error('maxAgeSeconds must be a non-negative safe integer.');
|
|
9
|
+
}
|
|
10
|
+
const parts = [
|
|
11
|
+
`${encodeURIComponent(input.name)}=${encodeURIComponent(input.value)}`,
|
|
12
|
+
];
|
|
13
|
+
if (options.path !== undefined) {
|
|
14
|
+
parts.push(`Path=${options.path}`);
|
|
15
|
+
}
|
|
16
|
+
if (options.domain !== undefined) {
|
|
17
|
+
parts.push(`Domain=${options.domain}`);
|
|
18
|
+
}
|
|
19
|
+
if (options.maxAgeSeconds !== undefined) {
|
|
20
|
+
parts.push(`Max-Age=${String(options.maxAgeSeconds)}`);
|
|
21
|
+
}
|
|
22
|
+
if (options.expires !== undefined) {
|
|
23
|
+
parts.push(`Expires=${options.expires.toUTCString()}`);
|
|
24
|
+
}
|
|
25
|
+
if (options.httpOnly) {
|
|
26
|
+
parts.push('HttpOnly');
|
|
27
|
+
}
|
|
28
|
+
if (options.secure) {
|
|
29
|
+
parts.push('Secure');
|
|
30
|
+
}
|
|
31
|
+
if (options.sameSite !== undefined) {
|
|
32
|
+
const formattedSameSite = options.sameSite.charAt(0).toUpperCase() + options.sameSite.slice(1);
|
|
33
|
+
parts.push(`SameSite=${formattedSameSite}`);
|
|
34
|
+
}
|
|
35
|
+
return parts.join('; ');
|
|
36
|
+
}
|
|
37
|
+
export function appendSetCookieHeader(res, serializedCookie) {
|
|
38
|
+
const existingValue = res.getHeader('Set-Cookie');
|
|
39
|
+
if (existingValue === undefined) {
|
|
40
|
+
res.setHeader('Set-Cookie', serializedCookie);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (Array.isArray(existingValue)) {
|
|
44
|
+
res.setHeader('Set-Cookie', [
|
|
45
|
+
...existingValue.map(String),
|
|
46
|
+
serializedCookie,
|
|
47
|
+
]);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (typeof existingValue === 'string') {
|
|
51
|
+
res.setHeader('Set-Cookie', [existingValue, serializedCookie]);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
res.setHeader('Set-Cookie', [String(existingValue), serializedCookie]);
|
|
55
|
+
}
|
|
56
|
+
export function setPagesCookie(res, input) {
|
|
57
|
+
const serializedCookie = serializeSetCookie(input);
|
|
58
|
+
appendSetCookieHeader(res, serializedCookie);
|
|
59
|
+
return serializedCookie;
|
|
60
|
+
}
|
|
61
|
+
export function setPagesAuthCookie(res, input) {
|
|
62
|
+
return setPagesCookie(res, {
|
|
63
|
+
name: input.name,
|
|
64
|
+
value: input.value,
|
|
65
|
+
options: {
|
|
66
|
+
path: input.path ?? '/',
|
|
67
|
+
maxAgeSeconds: input.maxAgeSeconds,
|
|
68
|
+
secure: input.secure ?? false,
|
|
69
|
+
httpOnly: true,
|
|
70
|
+
sameSite: input.sameSite ?? 'lax',
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
export function clearPagesAuthCookie(res, input) {
|
|
75
|
+
return setPagesCookie(res, {
|
|
76
|
+
name: input.name,
|
|
77
|
+
value: '',
|
|
78
|
+
options: {
|
|
79
|
+
path: input.path ?? '/',
|
|
80
|
+
maxAgeSeconds: 0,
|
|
81
|
+
expires: new Date(0),
|
|
82
|
+
secure: input.secure ?? false,
|
|
83
|
+
httpOnly: true,
|
|
84
|
+
sameSite: input.sameSite ?? 'lax',
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { NextApiHandler, NextApiRequest, NextApiResponse } from 'next';
|
|
2
|
+
import type { LoginMethodAdapter } from '../../core/adapters/login-method-adapter';
|
|
3
|
+
import type { DirectAuthService } from '../../core/services/direct-auth-service';
|
|
4
|
+
import type { AuthActor } from '../../core/types/auth-contract';
|
|
5
|
+
import { type CookieSameSite } from './cookies';
|
|
6
|
+
import { type DirectAccessTokenTransportConfig, type DirectCsrfConfig, type RefreshTokenSource } from '../shared/direct-auth-utils';
|
|
7
|
+
export type DirectCookieConfig = {
|
|
8
|
+
enabled?: boolean;
|
|
9
|
+
accessTokenCookieName?: string;
|
|
10
|
+
refreshTokenCookieName?: string;
|
|
11
|
+
path?: string;
|
|
12
|
+
sameSite?: CookieSameSite;
|
|
13
|
+
secure?: boolean;
|
|
14
|
+
secureInProduction?: boolean;
|
|
15
|
+
refreshTokenMaxAgeSeconds?: number;
|
|
16
|
+
};
|
|
17
|
+
export type PagesDirectLoginIssueResult = {
|
|
18
|
+
accessToken?: string;
|
|
19
|
+
accessClaims?: {
|
|
20
|
+
exp: number;
|
|
21
|
+
iat: number;
|
|
22
|
+
};
|
|
23
|
+
refreshToken?: string;
|
|
24
|
+
clientSession?: unknown;
|
|
25
|
+
body?: Record<string, unknown>;
|
|
26
|
+
redirectTo?: string;
|
|
27
|
+
statusCode?: number;
|
|
28
|
+
};
|
|
29
|
+
export type CreatePagesDirectAuthHandlersOptions<TSessionId, TUserId, TActor extends AuthActor = AuthActor> = {
|
|
30
|
+
directAuthService: DirectAuthService<TSessionId, TUserId, TActor>;
|
|
31
|
+
loginMethods?: Readonly<Record<string, LoginMethodAdapter<TUserId>>>;
|
|
32
|
+
issueLogin?: (input: {
|
|
33
|
+
req: NextApiRequest;
|
|
34
|
+
res: NextApiResponse;
|
|
35
|
+
requestId?: string;
|
|
36
|
+
method: string;
|
|
37
|
+
userId: TUserId;
|
|
38
|
+
}) => Promise<PagesDirectLoginIssueResult | void> | PagesDirectLoginIssueResult | void;
|
|
39
|
+
defaultLoginMethod?: string;
|
|
40
|
+
parseSessionId?: (value: unknown) => TSessionId | undefined;
|
|
41
|
+
accessTokenTransport?: DirectAccessTokenTransportConfig<TActor>;
|
|
42
|
+
refreshTokenFieldName?: string;
|
|
43
|
+
refreshTokenPriority?: readonly RefreshTokenSource[];
|
|
44
|
+
expectedAudience?: string;
|
|
45
|
+
allowedActors?: readonly TActor[] | ReadonlySet<TActor>;
|
|
46
|
+
csrf?: DirectCsrfConfig;
|
|
47
|
+
cookies?: DirectCookieConfig;
|
|
48
|
+
logoutAllowMissingCredentials?: boolean;
|
|
49
|
+
requestIdHeaderName?: string;
|
|
50
|
+
authorizationHeaderName?: string;
|
|
51
|
+
};
|
|
52
|
+
export type PagesDirectAuthHandlers = {
|
|
53
|
+
refresh: NextApiHandler;
|
|
54
|
+
logout: NextApiHandler;
|
|
55
|
+
loginStart: NextApiHandler;
|
|
56
|
+
loginFinish: NextApiHandler;
|
|
57
|
+
};
|
|
58
|
+
export declare function createPagesDirectAuthHandlers<TSessionId, TUserId, TActor extends AuthActor = AuthActor>(options: CreatePagesDirectAuthHandlersOptions<TSessionId, TUserId, TActor>): PagesDirectAuthHandlers;
|