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,67 @@
|
|
|
1
|
+
export function createInMemoryRefreshTokenAdapter() {
|
|
2
|
+
const records = new Map();
|
|
3
|
+
return {
|
|
4
|
+
async create(input) {
|
|
5
|
+
records.set(input.tokenHash, {
|
|
6
|
+
sessionId: input.sessionId,
|
|
7
|
+
tokenHash: input.tokenHash,
|
|
8
|
+
expiresAtUnix: input.expiresAtUnix,
|
|
9
|
+
familyId: input.familyId,
|
|
10
|
+
...(input.parentTokenHash === undefined
|
|
11
|
+
? {}
|
|
12
|
+
: { parentTokenHash: input.parentTokenHash }),
|
|
13
|
+
});
|
|
14
|
+
},
|
|
15
|
+
async find(tokenHash) {
|
|
16
|
+
const record = records.get(tokenHash);
|
|
17
|
+
if (!record) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
sessionId: record.sessionId,
|
|
22
|
+
familyId: record.familyId,
|
|
23
|
+
expiresAtUnix: record.expiresAtUnix,
|
|
24
|
+
...(record.revokedAtUnix === undefined
|
|
25
|
+
? {}
|
|
26
|
+
: { revokedAtUnix: record.revokedAtUnix }),
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
async consume(tokenHash, nowUnix) {
|
|
30
|
+
const record = records.get(tokenHash);
|
|
31
|
+
if (!record) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
if (record.consumedAtUnix === undefined ||
|
|
35
|
+
record.consumedAtUnix === null) {
|
|
36
|
+
record.consumedAtUnix = nowUnix;
|
|
37
|
+
records.set(tokenHash, record);
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
sessionId: record.sessionId,
|
|
41
|
+
familyId: record.familyId,
|
|
42
|
+
expiresAtUnix: record.expiresAtUnix,
|
|
43
|
+
consumedAtUnix: record.consumedAtUnix,
|
|
44
|
+
...(record.revokedAtUnix === undefined
|
|
45
|
+
? {}
|
|
46
|
+
: { revokedAtUnix: record.revokedAtUnix }),
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
async revoke(tokenHash, nowUnix) {
|
|
50
|
+
const record = records.get(tokenHash);
|
|
51
|
+
if (!record) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
record.revokedAtUnix = nowUnix;
|
|
55
|
+
records.set(tokenHash, record);
|
|
56
|
+
},
|
|
57
|
+
async revokeFamily(familyId, nowUnix) {
|
|
58
|
+
for (const [tokenHash, record] of records.entries()) {
|
|
59
|
+
if (record.familyId !== familyId) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
record.revokedAtUnix = nowUnix;
|
|
63
|
+
records.set(tokenHash, record);
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SessionAdapter } from '../../core/adapters/session-adapter';
|
|
2
|
+
import type { AuthActor } from '../../core/types/auth-contract';
|
|
3
|
+
export declare function createInMemorySessionAdapter<TSessionId, TUserId, TActor extends AuthActor, TServerSessionData extends Record<string, unknown> = Record<string, never>>(options: {
|
|
4
|
+
createSessionId: () => TSessionId;
|
|
5
|
+
nowUnix?: () => number;
|
|
6
|
+
}): SessionAdapter<TSessionId, TUserId, TActor, TServerSessionData>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export function createInMemorySessionAdapter(options) {
|
|
2
|
+
const records = new Map();
|
|
3
|
+
const nowUnix = options.nowUnix ?? (() => Math.floor(Date.now() / 1000));
|
|
4
|
+
const cloneRecord = (record) => ({
|
|
5
|
+
...record,
|
|
6
|
+
...(record.serverSessionData === undefined
|
|
7
|
+
? {}
|
|
8
|
+
: { serverSessionData: structuredClone(record.serverSessionData) }),
|
|
9
|
+
});
|
|
10
|
+
return {
|
|
11
|
+
async create(input) {
|
|
12
|
+
if (!Number.isSafeInteger(input.ttlSeconds) || input.ttlSeconds <= 0) {
|
|
13
|
+
throw new Error('ttlSeconds must be a positive safe integer.');
|
|
14
|
+
}
|
|
15
|
+
const issuedAtUnix = nowUnix();
|
|
16
|
+
const sessionRecord = {
|
|
17
|
+
sessionId: options.createSessionId(),
|
|
18
|
+
userId: input.userId,
|
|
19
|
+
actor: input.actor,
|
|
20
|
+
...(input.clientId === undefined ? {} : { clientId: input.clientId }),
|
|
21
|
+
issuedAt: issuedAtUnix,
|
|
22
|
+
expiresAt: issuedAtUnix + input.ttlSeconds,
|
|
23
|
+
...(input.serverSessionData === undefined
|
|
24
|
+
? {}
|
|
25
|
+
: { serverSessionData: structuredClone(input.serverSessionData) }),
|
|
26
|
+
};
|
|
27
|
+
records.set(sessionRecord.sessionId, sessionRecord);
|
|
28
|
+
return cloneRecord(sessionRecord);
|
|
29
|
+
},
|
|
30
|
+
async findById(sessionId) {
|
|
31
|
+
const record = records.get(sessionId);
|
|
32
|
+
return record ? cloneRecord(record) : null;
|
|
33
|
+
},
|
|
34
|
+
async revoke(sessionId, revokeUnix) {
|
|
35
|
+
const record = records.get(sessionId);
|
|
36
|
+
if (!record) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
record.revokedAt = revokeUnix;
|
|
40
|
+
records.set(sessionId, record);
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createInMemoryAccessTokenRevocationAdapter } from './in-memory-access-token-revocation-adapter';
|
|
2
|
+
export { createInMemoryAuthorizationCodeAdapter } from './in-memory-authorization-code-adapter';
|
|
3
|
+
export { createInMemoryOAuthClientAdapter, type InMemoryOAuthClient, } from './in-memory-oauth-client-adapter';
|
|
4
|
+
export { createInMemoryPendingAuthRequestAdapter } from './in-memory-pending-auth-request-adapter';
|
|
5
|
+
export { createInMemoryRefreshTokenAdapter } from './in-memory-refresh-token-adapter';
|
|
6
|
+
export { createInMemorySessionAdapter } from './in-memory-session-adapter';
|
|
7
|
+
export { createIncrementingIdFactory, createStepClock } from './test-fixtures';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createInMemoryAccessTokenRevocationAdapter } from './in-memory-access-token-revocation-adapter';
|
|
2
|
+
export { createInMemoryAuthorizationCodeAdapter } from './in-memory-authorization-code-adapter';
|
|
3
|
+
export { createInMemoryOAuthClientAdapter, } from './in-memory-oauth-client-adapter';
|
|
4
|
+
export { createInMemoryPendingAuthRequestAdapter } from './in-memory-pending-auth-request-adapter';
|
|
5
|
+
export { createInMemoryRefreshTokenAdapter } from './in-memory-refresh-token-adapter';
|
|
6
|
+
export { createInMemorySessionAdapter } from './in-memory-session-adapter';
|
|
7
|
+
export { createIncrementingIdFactory, createStepClock } from './test-fixtures';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function createStepClock(initialUnix) {
|
|
2
|
+
let currentUnix = initialUnix;
|
|
3
|
+
return {
|
|
4
|
+
nowUnix: () => currentUnix,
|
|
5
|
+
tick: (seconds = 1) => {
|
|
6
|
+
currentUnix += seconds;
|
|
7
|
+
return currentUnix;
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export function createIncrementingIdFactory(initialValue = 1) {
|
|
12
|
+
let current = initialValue;
|
|
13
|
+
return () => {
|
|
14
|
+
const next = current;
|
|
15
|
+
current += 1;
|
|
16
|
+
return next;
|
|
17
|
+
};
|
|
18
|
+
}
|