@venturekit/auth 0.0.37 → 0.0.39
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 +108 -0
- package/dist/migrations/vk_auth_004_api_keys.sql +38 -0
- package/dist/migrations/vk_auth_005_invitations.sql +37 -0
- package/dist/server/api-keys.d.ts +123 -0
- package/dist/server/api-keys.d.ts.map +1 -0
- package/dist/server/api-keys.js +209 -0
- package/dist/server/api-keys.js.map +1 -0
- package/dist/server/federated-routes.d.ts +18 -1
- package/dist/server/federated-routes.d.ts.map +1 -1
- package/dist/server/federated-routes.js +14 -2
- package/dist/server/federated-routes.js.map +1 -1
- package/dist/server/federated.d.ts +65 -5
- package/dist/server/federated.d.ts.map +1 -1
- package/dist/server/federated.js +44 -12
- package/dist/server/federated.js.map +1 -1
- package/dist/server/impersonation.d.ts +114 -0
- package/dist/server/impersonation.d.ts.map +1 -0
- package/dist/server/impersonation.js +173 -0
- package/dist/server/impersonation.js.map +1 -0
- package/dist/server/index.d.ts +9 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +8 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/invitations.d.ts +135 -0
- package/dist/server/invitations.d.ts.map +1 -0
- package/dist/server/invitations.js +241 -0
- package/dist/server/invitations.js.map +1 -0
- package/dist/server/passkeys.d.ts +86 -0
- package/dist/server/passkeys.d.ts.map +1 -0
- package/dist/server/passkeys.js +200 -0
- package/dist/server/passkeys.js.map +1 -0
- package/dist/server/sign-up.d.ts +16 -4
- package/dist/server/sign-up.d.ts.map +1 -1
- package/dist/server/sign-up.js +38 -9
- package/dist/server/sign-up.js.map +1 -1
- package/dist/server/store/postgres.d.ts.map +1 -1
- package/dist/server/store/postgres.js +13 -4
- package/dist/server/store/postgres.js.map +1 -1
- package/package.json +6 -6
- package/src/migrations/vk_auth_004_api_keys.sql +38 -0
- package/src/migrations/vk_auth_005_invitations.sql +37 -0
package/README.md
CHANGED
|
@@ -72,6 +72,114 @@ const cognitoConfig = createCognitoConfig(securityConfig);
|
|
|
72
72
|
const userPoolConfig = buildUserPoolConfig(cognitoConfig);
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
+
## Customer API keys
|
|
76
|
+
|
|
77
|
+
Machine-to-machine access to *your* API. A key carries its own scopes and goes
|
|
78
|
+
through the same `handler({ scopes })` gate as a JWT; only its SHA-256 is stored.
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import { createApiKey, apiKeyAuth } from '@venturekit/auth/server';
|
|
82
|
+
import { query } from '@venturekit/data';
|
|
83
|
+
|
|
84
|
+
// Issue (admin route) — the token is returned exactly once
|
|
85
|
+
const { key, token } = await createApiKey(query, {
|
|
86
|
+
name: 'CI deploy key', scopes: ['orders.read'], ownerId: ctx.user.id, tenantId: ctx.tenant?.id,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// Accept on a route: `X-Api-Key: vk_…` or `Authorization: Bearer vk_…`
|
|
90
|
+
export const main = handler(fn, {
|
|
91
|
+
scopes: ['orders.read'],
|
|
92
|
+
middleware: [apiKeyAuth({ querier: query })], // requests without a key fall through to JWT auth
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`verifyApiKey`, `listApiKeys`, `revokeApiKey` and `rotateApiKey` complete the
|
|
97
|
+
lifecycle. Table `vk_api_keys` ships with the package migrations.
|
|
98
|
+
|
|
99
|
+
## Invitations
|
|
100
|
+
|
|
101
|
+
Single-use, expiring "join as `<role>` in `<tenant>`" links that create the
|
|
102
|
+
Cognito account on acceptance. The package owns the token; your app owns the
|
|
103
|
+
e-mail and the membership row.
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import { createInvitation, getInvitationByToken, acceptInvitation } from '@venturekit/auth/server';
|
|
107
|
+
|
|
108
|
+
// Admin invites (in the admin route's transaction)
|
|
109
|
+
const { invitation, token } = await createInvitation(tx.query, {
|
|
110
|
+
email, tenantId: ctx.tenant.id, role: 'member', invitedBy: ctx.user.id,
|
|
111
|
+
});
|
|
112
|
+
await sendInviteEmail(email, `${APP_URL}/join?token=${token}`);
|
|
113
|
+
|
|
114
|
+
// Invitee opens the link → preview, then submits name + password (transactional route)
|
|
115
|
+
const preview = await getInvitationByToken(query, token); // null → expired / used
|
|
116
|
+
const { userSub, created } = await acceptInvitation(tx.query, { token, password, name });
|
|
117
|
+
await memberships.create(tx, { userSub, tenantId: invitation.tenantId, role: invitation.role });
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Acceptance claims the token atomically before any Cognito call (two concurrent
|
|
121
|
+
submits cannot both create the account); an address that already has an
|
|
122
|
+
account gets `409 invitation_email_taken` and accepts with `existingUserSub`
|
|
123
|
+
after signing in. Table `vk_invitations` ships with the package migrations.
|
|
124
|
+
|
|
125
|
+
## Passkeys (WebAuthn)
|
|
126
|
+
|
|
127
|
+
Declare `passkeys: { relyingPartyId: 'example.com' }` on the auth intent (needs the
|
|
128
|
+
`essentials`/`plus` plan — the `medium`/`large` presets) and the pool gains the
|
|
129
|
+
choice-based `USER_AUTH` flow with password *and* passkey as first factors.
|
|
130
|
+
Each flow is two server calls around one browser round-trip:
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
import {
|
|
134
|
+
beginPasskeyRegistration, completePasskeyRegistration, listPasskeys, deletePasskey,
|
|
135
|
+
beginPasskeySignIn, completePasskeySignIn,
|
|
136
|
+
} from '@venturekit/auth/server';
|
|
137
|
+
|
|
138
|
+
// Enrol (signed in): POST /auth/passkeys/begin → options; browser creates; POST /auth/passkeys/complete
|
|
139
|
+
const options = await beginPasskeyRegistration(accessToken);
|
|
140
|
+
// navigator.credentials.create({ publicKey: PublicKeyCredential.parseCreationOptionsFromJSON(options) })
|
|
141
|
+
await completePasskeyRegistration(accessToken, body.credential); // cred.toJSON(), unchanged
|
|
142
|
+
|
|
143
|
+
// Sign in (no password)
|
|
144
|
+
const { session, options } = await beginPasskeySignIn(email); // passkey_not_available → show the password form
|
|
145
|
+
// navigator.credentials.get({ publicKey: PublicKeyCredential.parseRequestOptionsFromJSON(options) })
|
|
146
|
+
const tokens = await completePasskeySignIn({ username: email, session, credential });
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
`completePasskeySignIn` returns the same `SignInResult` as `signInWithPassword`,
|
|
150
|
+
so the cookie helpers apply unchanged; a pool with MFA required chains its
|
|
151
|
+
second factor through the existing challenge helpers.
|
|
152
|
+
|
|
153
|
+
## Impersonation ("view as user")
|
|
154
|
+
|
|
155
|
+
A support agent sees the product as a user without holding that user's
|
|
156
|
+
credentials: the agent keeps their own session and presents a signed,
|
|
157
|
+
short-lived grant bound to their sub. The middleware swaps `ctx.user` to the
|
|
158
|
+
target, strips denied scopes, and stamps `claims.impersonated_by` so every
|
|
159
|
+
audit row and log line says who is really there.
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
import { issueImpersonationGrant, impersonationMiddleware, isImpersonated } from '@venturekit/auth/server';
|
|
163
|
+
|
|
164
|
+
// POST /admin/users/{id}/impersonate (scopes: ['admin.impersonate'])
|
|
165
|
+
const grant = issueImpersonationGrant({ adminSub: ctx.user.id, targetSub: user.sub, ttlSeconds: 900, reason: ticketId });
|
|
166
|
+
|
|
167
|
+
// every route — after auth, before authz/tenancy; the SPA sends the grant as `X-VK-Impersonate`
|
|
168
|
+
middleware: [
|
|
169
|
+
cookieAuthMiddleware(),
|
|
170
|
+
impersonationMiddleware({
|
|
171
|
+
resolveTarget: (sub) => users.principalFor(sub), // scopes + tenant claims the user would get
|
|
172
|
+
denyScopes: ['admin.*', 'billing.write'],
|
|
173
|
+
onImpersonate: ({ grant, ctx }) => audit.record({ action: 'impersonation.use', actor: grant.adminSub, target: grant.targetSub, path: ctx.path }),
|
|
174
|
+
}),
|
|
175
|
+
]
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Grants are HMAC-signed with `VENTURE_IMPERSONATION_SECRET` (falls back to the
|
|
179
|
+
internal-call HMAC secret every deployed function has), expire after 15 min by
|
|
180
|
+
default (1 h max), and an invalid or foreign grant answers 403 rather than
|
|
181
|
+
silently falling back to the admin's own identity.
|
|
182
|
+
|
|
75
183
|
## API Reference
|
|
76
184
|
|
|
77
185
|
See the [API reference](https://venturekit.dev/api-reference/auth) for full documentation.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
-- @venturekit/auth — customer API keys (inbound machine-to-machine auth).
|
|
2
|
+
--
|
|
3
|
+
-- A key is `vk_<prefix><secret>`; only the SHA-256 of the full token is
|
|
4
|
+
-- stored, so a database read-out yields nothing usable. `prefix` (the
|
|
5
|
+
-- first 12 characters, non-secret) is what admin screens display and what
|
|
6
|
+
-- `verifyApiKey` uses to narrow the lookup before the constant-time hash
|
|
7
|
+
-- compare.
|
|
8
|
+
--
|
|
9
|
+
-- `owner_id` is the Cognito sub the key ACTS AS (its scopes are the key's
|
|
10
|
+
-- own, never inherited); `tenant_id` scopes it to one tenant. Both are
|
|
11
|
+
-- nullable TEXT so single-tenant / service keys fit, and apps may add RLS
|
|
12
|
+
-- on top. `scopes` feed `handler({ scopes })` exactly like JWT scopes.
|
|
13
|
+
|
|
14
|
+
CREATE TABLE IF NOT EXISTS vk_api_keys (
|
|
15
|
+
id TEXT PRIMARY KEY,
|
|
16
|
+
prefix TEXT NOT NULL,
|
|
17
|
+
key_hash TEXT NOT NULL UNIQUE,
|
|
18
|
+
name TEXT NOT NULL,
|
|
19
|
+
owner_id TEXT,
|
|
20
|
+
tenant_id TEXT,
|
|
21
|
+
scopes TEXT[] NOT NULL DEFAULT '{}',
|
|
22
|
+
metadata JSONB NOT NULL DEFAULT '{}'::jsonb,
|
|
23
|
+
expires_at TIMESTAMPTZ,
|
|
24
|
+
last_used_at TIMESTAMPTZ,
|
|
25
|
+
revoked_at TIMESTAMPTZ,
|
|
26
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
CREATE INDEX IF NOT EXISTS vk_api_keys_owner_idx
|
|
30
|
+
ON vk_api_keys (owner_id)
|
|
31
|
+
WHERE revoked_at IS NULL;
|
|
32
|
+
|
|
33
|
+
CREATE INDEX IF NOT EXISTS vk_api_keys_tenant_idx
|
|
34
|
+
ON vk_api_keys (tenant_id)
|
|
35
|
+
WHERE revoked_at IS NULL;
|
|
36
|
+
|
|
37
|
+
COMMENT ON TABLE vk_api_keys IS
|
|
38
|
+
'Customer / service API keys — hashed. Structure owned by @venturekit/auth; issued and verified through its api-keys helpers.';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
-- @venturekit/auth — invitations.
|
|
2
|
+
--
|
|
3
|
+
-- A single-use, expiring token that lets an invited person create (or
|
|
4
|
+
-- attach) their account with the role / tenant the inviter chose. Only
|
|
5
|
+
-- the SHA-256 of the token is stored; the plaintext travels in the invite
|
|
6
|
+
-- e-mail link and nowhere else.
|
|
7
|
+
--
|
|
8
|
+
-- `tenant_id`, `role` and `metadata` are opaque to the framework: the app
|
|
9
|
+
-- reads them back from the accepted invitation (`acceptInvitation` returns
|
|
10
|
+
-- the row) to create its membership / profile rows in the same
|
|
11
|
+
-- transaction. `email` is lower-cased on write.
|
|
12
|
+
|
|
13
|
+
CREATE TABLE IF NOT EXISTS vk_invitations (
|
|
14
|
+
id TEXT PRIMARY KEY,
|
|
15
|
+
token_hash TEXT NOT NULL UNIQUE,
|
|
16
|
+
email TEXT NOT NULL,
|
|
17
|
+
tenant_id TEXT,
|
|
18
|
+
role TEXT,
|
|
19
|
+
invited_by TEXT,
|
|
20
|
+
metadata JSONB NOT NULL DEFAULT '{}'::jsonb,
|
|
21
|
+
expires_at TIMESTAMPTZ NOT NULL,
|
|
22
|
+
accepted_at TIMESTAMPTZ,
|
|
23
|
+
accepted_by TEXT,
|
|
24
|
+
revoked_at TIMESTAMPTZ,
|
|
25
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
-- "Is there an open invitation for this address (in this tenant)?"
|
|
29
|
+
CREATE INDEX IF NOT EXISTS vk_invitations_open_email_idx
|
|
30
|
+
ON vk_invitations (email, tenant_id)
|
|
31
|
+
WHERE accepted_at IS NULL AND revoked_at IS NULL;
|
|
32
|
+
|
|
33
|
+
CREATE INDEX IF NOT EXISTS vk_invitations_tenant_idx
|
|
34
|
+
ON vk_invitations (tenant_id, created_at DESC);
|
|
35
|
+
|
|
36
|
+
COMMENT ON TABLE vk_invitations IS
|
|
37
|
+
'Single-use invitation tokens (hashed). Structure owned by @venturekit/auth; issued / accepted through its invitations helpers.';
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Customer API keys — inbound machine-to-machine authentication for YOUR
|
|
3
|
+
* API (a customer's backend calling you), as opposed to
|
|
4
|
+
* `@venturekit/integrations`' `apiKey()`, which manages keys you hold for
|
|
5
|
+
* THIRD-PARTY APIs.
|
|
6
|
+
*
|
|
7
|
+
* Model
|
|
8
|
+
* -----
|
|
9
|
+
* A key is issued once ({@link createApiKey}) and shown to the customer once;
|
|
10
|
+
* the database keeps only its SHA-256 hash plus a non-secret `prefix` for
|
|
11
|
+
* display. A key carries its own `scopes`, so it plugs into the same
|
|
12
|
+
* `handler({ scopes: [...] })` gate as a JWT — the route does not care
|
|
13
|
+
* which credential it got. Keys can be tenant-scoped, expire, and be
|
|
14
|
+
* revoked; `lastUsedAt` is touched on use for hygiene reports.
|
|
15
|
+
*
|
|
16
|
+
* Wire it up
|
|
17
|
+
* ----------
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { apiKeyAuth } from '@venturekit/auth/server';
|
|
20
|
+
* import { query } from '@venturekit/data';
|
|
21
|
+
*
|
|
22
|
+
* export const main = handler(fn, {
|
|
23
|
+
* scopes: ['orders.read'],
|
|
24
|
+
* middleware: [apiKeyAuth({ querier: query })], // before the default JWT auth
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
* The middleware only acts when a key is presented (`X-Api-Key` header or
|
|
28
|
+
* `Authorization: Bearer vk_…`); otherwise it passes through and the
|
|
29
|
+
* cookie / JWT middleware runs as usual, so one route can serve both.
|
|
30
|
+
*
|
|
31
|
+
* Tables: `vk_api_keys` (this package's migrations).
|
|
32
|
+
*/
|
|
33
|
+
import type { Middleware, RequestContext } from '@venturekit/runtime';
|
|
34
|
+
/** Same shape as the role-scopes helpers: `@venturekit/data`'s `query` fits. */
|
|
35
|
+
export type Querier = <T = Record<string, unknown>[]>(sql: string, params?: unknown[]) => Promise<T>;
|
|
36
|
+
export interface ApiKeyRecord {
|
|
37
|
+
id: string;
|
|
38
|
+
/** Non-secret display prefix, e.g. `vk_3fA9kQ2pLm`. */
|
|
39
|
+
prefix: string;
|
|
40
|
+
name: string;
|
|
41
|
+
ownerId: string | null;
|
|
42
|
+
tenantId: string | null;
|
|
43
|
+
scopes: string[];
|
|
44
|
+
metadata: Record<string, unknown>;
|
|
45
|
+
expiresAt: Date | null;
|
|
46
|
+
lastUsedAt: Date | null;
|
|
47
|
+
revokedAt: Date | null;
|
|
48
|
+
createdAt: Date;
|
|
49
|
+
}
|
|
50
|
+
export interface CreateApiKeyInput {
|
|
51
|
+
/** Human label ("CI deploy key"). */
|
|
52
|
+
name: string;
|
|
53
|
+
scopes: string[];
|
|
54
|
+
/** Cognito sub the key acts as — `ctx.user.id` for requests it authenticates. */
|
|
55
|
+
ownerId?: string | null;
|
|
56
|
+
tenantId?: string | null;
|
|
57
|
+
metadata?: Record<string, unknown>;
|
|
58
|
+
/** Absolute expiry; omit for a non-expiring key. */
|
|
59
|
+
expiresAt?: Date | null;
|
|
60
|
+
}
|
|
61
|
+
/** Token prefix — lets a scanner (and `apiKeyAuth`) recognise a key on sight. */
|
|
62
|
+
export declare const API_KEY_TOKEN_PREFIX = "vk_";
|
|
63
|
+
/** `vk_` + 32 random bytes, base64url (43 chars). */
|
|
64
|
+
export declare function generateApiKeyToken(): string;
|
|
65
|
+
export declare function hashApiKeyToken(token: string): string;
|
|
66
|
+
/** True when a string looks like one of our tokens (cheap pre-check, no I/O). */
|
|
67
|
+
export declare function looksLikeApiKeyToken(value: string | undefined | null): value is string;
|
|
68
|
+
/**
|
|
69
|
+
* Issue a key. Returns the record and the plaintext `token` — the only time
|
|
70
|
+
* it is available.
|
|
71
|
+
*/
|
|
72
|
+
export declare function createApiKey(querier: Querier, input: CreateApiKeyInput): Promise<{
|
|
73
|
+
key: ApiKeyRecord;
|
|
74
|
+
token: string;
|
|
75
|
+
}>;
|
|
76
|
+
/**
|
|
77
|
+
* Resolve a presented token to its live record, or `null` when unknown,
|
|
78
|
+
* revoked or expired. Looks up by hash (indexed, unique) and re-compares
|
|
79
|
+
* the hash in constant time so the database's own string compare is not
|
|
80
|
+
* the last word.
|
|
81
|
+
*/
|
|
82
|
+
export declare function verifyApiKey(querier: Querier, token: string, options?: {
|
|
83
|
+
touch?: boolean;
|
|
84
|
+
now?: Date;
|
|
85
|
+
}): Promise<ApiKeyRecord | null>;
|
|
86
|
+
export declare function listApiKeys(querier: Querier, filter?: {
|
|
87
|
+
ownerId?: string;
|
|
88
|
+
tenantId?: string | null;
|
|
89
|
+
includeRevoked?: boolean;
|
|
90
|
+
}): Promise<ApiKeyRecord[]>;
|
|
91
|
+
/** Revoke immediately. Idempotent; returns `false` when the id is unknown. */
|
|
92
|
+
export declare function revokeApiKey(querier: Querier, id: string): Promise<boolean>;
|
|
93
|
+
/**
|
|
94
|
+
* Rotate: issue a new key with the same name / owner / tenant / scopes /
|
|
95
|
+
* metadata and revoke the old one. Returns the new plaintext token once.
|
|
96
|
+
*/
|
|
97
|
+
export declare function rotateApiKey(querier: Querier, id: string, options?: {
|
|
98
|
+
expiresAt?: Date | null;
|
|
99
|
+
}): Promise<{
|
|
100
|
+
key: ApiKeyRecord;
|
|
101
|
+
token: string;
|
|
102
|
+
} | null>;
|
|
103
|
+
export interface ApiKeyAuthOptions {
|
|
104
|
+
querier: Querier;
|
|
105
|
+
/** Header carrying the raw key. Default `x-api-key`; `Authorization: Bearer vk_…` is always accepted too. */
|
|
106
|
+
headerName?: string;
|
|
107
|
+
/**
|
|
108
|
+
* When a key IS presented but is unknown / revoked / expired: `'reject'`
|
|
109
|
+
* (default) answers 401 immediately; `'ignore'` leaves `ctx.user` null so
|
|
110
|
+
* another auth middleware may still succeed.
|
|
111
|
+
*/
|
|
112
|
+
onInvalid?: 'reject' | 'ignore';
|
|
113
|
+
/** Skip the `last_used_at` stamp (high-volume routes). */
|
|
114
|
+
touch?: boolean;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Authenticate a request by API key. Populates `ctx.user` as
|
|
118
|
+
* `{ id: ownerId ?? key.id, scopes: key.scopes, claims: { apiKeyId, tenantId, … } }`
|
|
119
|
+
* so the runtime's `scopes` gate and tenancy middleware see an ordinary
|
|
120
|
+
* principal. Requests without a key pass through untouched.
|
|
121
|
+
*/
|
|
122
|
+
export declare function apiKeyAuth(options: ApiKeyAuthOptions): Middleware<RequestContext>;
|
|
123
|
+
//# sourceMappingURL=api-keys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-keys.d.ts","sourceRoot":"","sources":["../../src/server/api-keys.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAEtE,gFAAgF;AAChF,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAClD,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,OAAO,EAAE,KACf,OAAO,CAAC,CAAC,CAAC,CAAC;AAEhB,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,uDAAuD;IACvD,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,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CAAC,EAAE,OAAO,CAAC;IAAC,GAAG,CAAC,EAAE,IAAI,CAAA;CAAO,GAC5C,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAqB9B;AAED,wBAAsB,WAAW,CAC/B,OAAO,EAAE,OAAO,EAChB,MAAM,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,cAAc,CAAC,EAAE,OAAO,CAAA;CAAO,GACpF,OAAO,CAAC,YAAY,EAAE,CAAC,CAqBzB;AAED,8EAA8E;AAC9E,wBAAsB,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAMjF;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE,OAAO,EAChB,EAAE,EAAE,MAAM,EACV,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,IAAI,GAAG,IAAI,CAAA;CAAO,GACxC,OAAO,CAAC;IAAE,GAAG,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CActD;AAMD,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,6GAA6G;IAC7G,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,SAAS,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAChC,0DAA0D;IAC1D,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,UAAU,CAAC,cAAc,CAAC,CA0CjF"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Customer API keys — inbound machine-to-machine authentication for YOUR
|
|
3
|
+
* API (a customer's backend calling you), as opposed to
|
|
4
|
+
* `@venturekit/integrations`' `apiKey()`, which manages keys you hold for
|
|
5
|
+
* THIRD-PARTY APIs.
|
|
6
|
+
*
|
|
7
|
+
* Model
|
|
8
|
+
* -----
|
|
9
|
+
* A key is issued once ({@link createApiKey}) and shown to the customer once;
|
|
10
|
+
* the database keeps only its SHA-256 hash plus a non-secret `prefix` for
|
|
11
|
+
* display. A key carries its own `scopes`, so it plugs into the same
|
|
12
|
+
* `handler({ scopes: [...] })` gate as a JWT — the route does not care
|
|
13
|
+
* which credential it got. Keys can be tenant-scoped, expire, and be
|
|
14
|
+
* revoked; `lastUsedAt` is touched on use for hygiene reports.
|
|
15
|
+
*
|
|
16
|
+
* Wire it up
|
|
17
|
+
* ----------
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { apiKeyAuth } from '@venturekit/auth/server';
|
|
20
|
+
* import { query } from '@venturekit/data';
|
|
21
|
+
*
|
|
22
|
+
* export const main = handler(fn, {
|
|
23
|
+
* scopes: ['orders.read'],
|
|
24
|
+
* middleware: [apiKeyAuth({ querier: query })], // before the default JWT auth
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
* The middleware only acts when a key is presented (`X-Api-Key` header or
|
|
28
|
+
* `Authorization: Bearer vk_…`); otherwise it passes through and the
|
|
29
|
+
* cookie / JWT middleware runs as usual, so one route can serve both.
|
|
30
|
+
*
|
|
31
|
+
* Tables: `vk_api_keys` (this package's migrations).
|
|
32
|
+
*/
|
|
33
|
+
import { createHash, randomBytes, randomUUID, timingSafeEqual } from 'node:crypto';
|
|
34
|
+
/** Token prefix — lets a scanner (and `apiKeyAuth`) recognise a key on sight. */
|
|
35
|
+
export const API_KEY_TOKEN_PREFIX = 'vk_';
|
|
36
|
+
/** Characters of the token stored/displayed as the non-secret prefix. */
|
|
37
|
+
const DISPLAY_PREFIX_LENGTH = 12;
|
|
38
|
+
const KEY_COLUMNS = `
|
|
39
|
+
id,
|
|
40
|
+
prefix,
|
|
41
|
+
name,
|
|
42
|
+
owner_id AS "ownerId",
|
|
43
|
+
tenant_id AS "tenantId",
|
|
44
|
+
scopes,
|
|
45
|
+
metadata,
|
|
46
|
+
expires_at AS "expiresAt",
|
|
47
|
+
last_used_at AS "lastUsedAt",
|
|
48
|
+
revoked_at AS "revokedAt",
|
|
49
|
+
created_at AS "createdAt"`;
|
|
50
|
+
/** `vk_` + 32 random bytes, base64url (43 chars). */
|
|
51
|
+
export function generateApiKeyToken() {
|
|
52
|
+
return `${API_KEY_TOKEN_PREFIX}${randomBytes(32).toString('base64url')}`;
|
|
53
|
+
}
|
|
54
|
+
export function hashApiKeyToken(token) {
|
|
55
|
+
return createHash('sha256').update(token, 'utf8').digest('hex');
|
|
56
|
+
}
|
|
57
|
+
/** True when a string looks like one of our tokens (cheap pre-check, no I/O). */
|
|
58
|
+
export function looksLikeApiKeyToken(value) {
|
|
59
|
+
return typeof value === 'string' && value.startsWith(API_KEY_TOKEN_PREFIX) && value.length >= 20 && value.length <= 128;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Issue a key. Returns the record and the plaintext `token` — the only time
|
|
63
|
+
* it is available.
|
|
64
|
+
*/
|
|
65
|
+
export async function createApiKey(querier, input) {
|
|
66
|
+
if (!input.name?.trim())
|
|
67
|
+
throw new Error('[venturekit/auth] createApiKey: name is required');
|
|
68
|
+
const token = generateApiKeyToken();
|
|
69
|
+
const rows = await querier(`INSERT INTO vk_api_keys (id, prefix, key_hash, name, owner_id, tenant_id, scopes, metadata, expires_at)
|
|
70
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8::jsonb, $9)
|
|
71
|
+
RETURNING ${KEY_COLUMNS}`, [
|
|
72
|
+
randomUUID(),
|
|
73
|
+
token.slice(0, DISPLAY_PREFIX_LENGTH),
|
|
74
|
+
hashApiKeyToken(token),
|
|
75
|
+
input.name.trim(),
|
|
76
|
+
input.ownerId ?? null,
|
|
77
|
+
input.tenantId ?? null,
|
|
78
|
+
input.scopes ?? [],
|
|
79
|
+
JSON.stringify(input.metadata ?? {}),
|
|
80
|
+
input.expiresAt ?? null,
|
|
81
|
+
]);
|
|
82
|
+
return { key: rows[0], token };
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Resolve a presented token to its live record, or `null` when unknown,
|
|
86
|
+
* revoked or expired. Looks up by hash (indexed, unique) and re-compares
|
|
87
|
+
* the hash in constant time so the database's own string compare is not
|
|
88
|
+
* the last word.
|
|
89
|
+
*/
|
|
90
|
+
export async function verifyApiKey(querier, token, options = {}) {
|
|
91
|
+
if (!looksLikeApiKeyToken(token))
|
|
92
|
+
return null;
|
|
93
|
+
const hash = hashApiKeyToken(token);
|
|
94
|
+
const rows = await querier(`SELECT ${KEY_COLUMNS}, key_hash AS "keyHash" FROM vk_api_keys WHERE key_hash = $1`, [hash]);
|
|
95
|
+
const row = rows[0];
|
|
96
|
+
if (!row)
|
|
97
|
+
return null;
|
|
98
|
+
const a = Buffer.from(row.keyHash, 'utf8');
|
|
99
|
+
const b = Buffer.from(hash, 'utf8');
|
|
100
|
+
if (a.length !== b.length || !timingSafeEqual(a, b))
|
|
101
|
+
return null;
|
|
102
|
+
const now = options.now ?? new Date();
|
|
103
|
+
if (row.revokedAt)
|
|
104
|
+
return null;
|
|
105
|
+
if (row.expiresAt && new Date(row.expiresAt).getTime() <= now.getTime())
|
|
106
|
+
return null;
|
|
107
|
+
if (options.touch !== false) {
|
|
108
|
+
// Fire-and-forget hygiene stamp; a failure here must not fail the request.
|
|
109
|
+
querier(`UPDATE vk_api_keys SET last_used_at = now() WHERE id = $1`, [row.id]).catch(() => undefined);
|
|
110
|
+
}
|
|
111
|
+
const { keyHash: _omit, ...record } = row;
|
|
112
|
+
return record;
|
|
113
|
+
}
|
|
114
|
+
export async function listApiKeys(querier, filter = {}) {
|
|
115
|
+
const where = [];
|
|
116
|
+
const params = [];
|
|
117
|
+
if (filter.ownerId !== undefined) {
|
|
118
|
+
params.push(filter.ownerId);
|
|
119
|
+
where.push(`owner_id = $${params.length}`);
|
|
120
|
+
}
|
|
121
|
+
if (filter.tenantId !== undefined) {
|
|
122
|
+
if (filter.tenantId === null)
|
|
123
|
+
where.push('tenant_id IS NULL');
|
|
124
|
+
else {
|
|
125
|
+
params.push(filter.tenantId);
|
|
126
|
+
where.push(`tenant_id = $${params.length}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (!filter.includeRevoked)
|
|
130
|
+
where.push('revoked_at IS NULL');
|
|
131
|
+
return querier(`SELECT ${KEY_COLUMNS} FROM vk_api_keys
|
|
132
|
+
${where.length ? `WHERE ${where.join(' AND ')}` : ''}
|
|
133
|
+
ORDER BY created_at DESC`, params);
|
|
134
|
+
}
|
|
135
|
+
/** Revoke immediately. Idempotent; returns `false` when the id is unknown. */
|
|
136
|
+
export async function revokeApiKey(querier, id) {
|
|
137
|
+
const rows = await querier(`UPDATE vk_api_keys SET revoked_at = COALESCE(revoked_at, now()) WHERE id = $1 RETURNING id`, [id]);
|
|
138
|
+
return rows.length > 0;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Rotate: issue a new key with the same name / owner / tenant / scopes /
|
|
142
|
+
* metadata and revoke the old one. Returns the new plaintext token once.
|
|
143
|
+
*/
|
|
144
|
+
export async function rotateApiKey(querier, id, options = {}) {
|
|
145
|
+
const rows = await querier(`SELECT ${KEY_COLUMNS} FROM vk_api_keys WHERE id = $1`, [id]);
|
|
146
|
+
const old = rows[0];
|
|
147
|
+
if (!old)
|
|
148
|
+
return null;
|
|
149
|
+
const issued = await createApiKey(querier, {
|
|
150
|
+
name: old.name,
|
|
151
|
+
scopes: old.scopes,
|
|
152
|
+
ownerId: old.ownerId,
|
|
153
|
+
tenantId: old.tenantId,
|
|
154
|
+
metadata: old.metadata,
|
|
155
|
+
expiresAt: options.expiresAt !== undefined ? options.expiresAt : old.expiresAt,
|
|
156
|
+
});
|
|
157
|
+
await revokeApiKey(querier, id);
|
|
158
|
+
return issued;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Authenticate a request by API key. Populates `ctx.user` as
|
|
162
|
+
* `{ id: ownerId ?? key.id, scopes: key.scopes, claims: { apiKeyId, tenantId, … } }`
|
|
163
|
+
* so the runtime's `scopes` gate and tenancy middleware see an ordinary
|
|
164
|
+
* principal. Requests without a key pass through untouched.
|
|
165
|
+
*/
|
|
166
|
+
export function apiKeyAuth(options) {
|
|
167
|
+
const headerName = (options.headerName ?? 'x-api-key').toLowerCase();
|
|
168
|
+
const onInvalid = options.onInvalid ?? 'reject';
|
|
169
|
+
return {
|
|
170
|
+
name: 'apiKeyAuth',
|
|
171
|
+
fn: async (ctx, next) => {
|
|
172
|
+
const headers = ctx.rawEvent.headers ?? {};
|
|
173
|
+
let token = headers[headerName]?.trim();
|
|
174
|
+
if (!token) {
|
|
175
|
+
const auth = headers['authorization']?.trim();
|
|
176
|
+
if (auth && /^bearer\s+/i.test(auth)) {
|
|
177
|
+
const bearer = auth.replace(/^bearer\s+/i, '');
|
|
178
|
+
if (looksLikeApiKeyToken(bearer))
|
|
179
|
+
token = bearer;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (!token)
|
|
183
|
+
return next();
|
|
184
|
+
const key = await verifyApiKey(options.querier, token, { touch: options.touch });
|
|
185
|
+
if (!key) {
|
|
186
|
+
if (onInvalid === 'ignore')
|
|
187
|
+
return next();
|
|
188
|
+
return {
|
|
189
|
+
statusCode: 401,
|
|
190
|
+
headers: { 'content-type': 'application/json' },
|
|
191
|
+
body: JSON.stringify({ error: { code: 'UNAUTHORIZED', message: 'Invalid API key' } }),
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
ctx.user = {
|
|
195
|
+
id: key.ownerId ?? key.id,
|
|
196
|
+
scopes: key.scopes,
|
|
197
|
+
claims: {
|
|
198
|
+
auth_method: 'api_key',
|
|
199
|
+
api_key_id: key.id,
|
|
200
|
+
api_key_name: key.name,
|
|
201
|
+
...(key.tenantId ? { tenant_id: key.tenantId } : {}),
|
|
202
|
+
...key.metadata,
|
|
203
|
+
},
|
|
204
|
+
};
|
|
205
|
+
return next();
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=api-keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-keys.js","sourceRoot":"","sources":["../../src/server/api-keys.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAoCnF,iFAAiF;AACjF,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,CAAC;AAC1C,yEAAyE;AACzE,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAEjC,MAAM,WAAW,GAAG;;;;;;;;;;;8BAWU,CAAC;AAE/B,qDAAqD;AACrD,MAAM,UAAU,mBAAmB;IACjC,OAAO,GAAG,oBAAoB,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,KAAa;IAC3C,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAClE,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,oBAAoB,CAAC,KAAgC;IACnE,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,UAAU,CAAC,oBAAoB,CAAC,IAAI,KAAK,CAAC,MAAM,IAAI,EAAE,IAAI,KAAK,CAAC,MAAM,IAAI,GAAG,CAAC;AAC1H,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,OAAgB,EAChB,KAAwB;IAExB,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC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AO;oBACL,UAAU,EAAE,GAAG;oBACf,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;oBAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,iBAAiB,EAAE,EAAE,CAAC;iBACtF,CAAC;YACJ,CAAC;YAED,GAAG,CAAC,IAAI,GAAG;gBACT,EAAE,EAAE,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,EAAE;gBACzB,MAAM,EAAE,GAAG,CAAC,MAAM;gBAClB,MAAM,EAAE;oBACN,WAAW,EAAE,SAAS;oBACtB,UAAU,EAAE,GAAG,CAAC,EAAE;oBAClB,YAAY,EAAE,GAAG,CAAC,IAAI;oBACtB,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;oBACpD,GAAG,GAAG,CAAC,QAAQ;iBAChB;aACF,CAAC;YACF,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -27,7 +27,7 @@ import { type APIGatewayProxyEventV2, type APIGatewayProxyResultV2, type Context
|
|
|
27
27
|
import { type RequestContext } from '@venturekit/runtime';
|
|
28
28
|
import { type CookieOptions } from './cookies.js';
|
|
29
29
|
import { type AuthServerConfig } from './config.js';
|
|
30
|
-
import { type FederatedProfile, type FederatedProvider } from './federated.js';
|
|
30
|
+
import { type ExistingPasswordAccountPolicy, type FederatedProfile, type FederatedProvider } from './federated.js';
|
|
31
31
|
/**
|
|
32
32
|
* Body shape for the `start` route.
|
|
33
33
|
*/
|
|
@@ -61,6 +61,15 @@ export interface FederatedOnSignInArgs {
|
|
|
61
61
|
* true), `ctx.rawEvent.headers`, etc.
|
|
62
62
|
*/
|
|
63
63
|
ctx: RequestContext;
|
|
64
|
+
/**
|
|
65
|
+
* `true` when this sign-in converted an existing PASSWORD account into
|
|
66
|
+
* a federation-managed one — the user's own password was replaced (see
|
|
67
|
+
* {@link FederatedAuthRoutesOptions.onExistingPasswordAccount}). Notify
|
|
68
|
+
* the user from this hook.
|
|
69
|
+
*/
|
|
70
|
+
accountLinked: boolean;
|
|
71
|
+
/** `true` when the Cognito user was created by this sign-in. */
|
|
72
|
+
created: boolean;
|
|
64
73
|
}
|
|
65
74
|
/**
|
|
66
75
|
* Whatever the `onSignIn` hook returns is merged into the response
|
|
@@ -87,6 +96,14 @@ export interface FederatedAuthRoutesOptions {
|
|
|
87
96
|
* transactions.
|
|
88
97
|
*/
|
|
89
98
|
transactional?: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* What to do when the IdP-verified email belongs to an existing
|
|
101
|
+
* PASSWORD account: `'link'` (default) replaces that password and
|
|
102
|
+
* signs the user in — `onSignIn` receives `accountLinked: true` so the
|
|
103
|
+
* app can tell them; `'reject'` answers 409 `federated_account_exists`
|
|
104
|
+
* and leaves the account untouched. See `signInAsFederatedUser`.
|
|
105
|
+
*/
|
|
106
|
+
onExistingPasswordAccount?: ExistingPasswordAccountPolicy;
|
|
90
107
|
/**
|
|
91
108
|
* Extra middleware to run inside each emitted handler, before the
|
|
92
109
|
* route body. Most apps put a tenancy middleware here so
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"federated-routes.d.ts","sourceRoot":"","sources":["../../src/server/federated-routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,EACL,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,OAAO,IAAI,aAAa,EAC9B,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,KAAK,cAAc,EAMpB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,KAAK,aAAa,EASnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAwB,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EAMvB,MAAM,gBAAgB,CAAC;AAIxB;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,6DAA6D;IAC7D,OAAO,EAAE,gBAAgB,CAAC;IAC1B,0DAA0D;IAC1D,UAAU,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,GAAG,EAAE,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"federated-routes.d.ts","sourceRoot":"","sources":["../../src/server/federated-routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,EACL,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,OAAO,IAAI,aAAa,EAC9B,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,KAAK,cAAc,EAMpB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,KAAK,aAAa,EASnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAwB,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EACL,KAAK,6BAA6B,EAClC,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EAMvB,MAAM,gBAAgB,CAAC;AAIxB;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,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AAC,uBAAuB,CAAC,CAAC;IACtC,QAAQ,EAAE,CACR,KAAK,EAAE,sBAAsB,EAC7B,OAAO,EAAE,aAAa,KACnB,OAAO,CAAC,uBAAuB,CAAC,CAAC;IACtC,MAAM,EAAE,CACN,KAAK,EAAE,sBAAsB,EAC7B,OAAO,EAAE,aAAa,KACnB,OAAO,CAAC,uBAAuB,CAAC,CAAC;CACvC;AAwCD,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,0BAA0B,GAClC,mBAAmB,CAoJrB"}
|
|
@@ -88,7 +88,13 @@ export function createFederatedAuthRoutes(options) {
|
|
|
88
88
|
code: body.code,
|
|
89
89
|
redirectUri: body.redirectUri,
|
|
90
90
|
});
|
|
91
|
-
const tokens = await signInAsFederatedUser({
|
|
91
|
+
const tokens = await signInAsFederatedUser({
|
|
92
|
+
provider,
|
|
93
|
+
profile,
|
|
94
|
+
...(options.onExistingPasswordAccount
|
|
95
|
+
? { onExistingPasswordAccount: options.onExistingPasswordAccount }
|
|
96
|
+
: {}),
|
|
97
|
+
}, options.config);
|
|
92
98
|
const config = options.config ?? loadAuthServerConfig();
|
|
93
99
|
const claims = await verifyAndDecode(tokens.idToken, {
|
|
94
100
|
userPoolId: config.userPoolId,
|
|
@@ -104,7 +110,13 @@ export function createFederatedAuthRoutes(options) {
|
|
|
104
110
|
}
|
|
105
111
|
let appResult;
|
|
106
112
|
if (options.onSignIn) {
|
|
107
|
-
appResult = await options.onSignIn({
|
|
113
|
+
appResult = await options.onSignIn({
|
|
114
|
+
profile,
|
|
115
|
+
cognitoSub,
|
|
116
|
+
ctx,
|
|
117
|
+
accountLinked: tokens.accountLinked,
|
|
118
|
+
created: tokens.created,
|
|
119
|
+
});
|
|
108
120
|
}
|
|
109
121
|
const cookieOptions = cookieOptionsFor(ctx);
|
|
110
122
|
for (const cookie of buildSessionCookies(tokens, cookieOptions)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"federated-routes.js","sourceRoot":"","sources":["../../src/server/federated-routes.ts"],"names":[],"mappings":"AA+BA,OAAO,EAEL,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,OAAO,EACP,SAAS,GACV,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAGL,qBAAqB,EACrB,wBAAwB,EACxB,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,oBAAoB,EAAyB,MAAM,aAAa,CAAC;AAC1E,OAAO,
|
|
1
|
+
{"version":3,"file":"federated-routes.js","sourceRoot":"","sources":["../../src/server/federated-routes.ts"],"names":[],"mappings":"AA+BA,OAAO,EAEL,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,OAAO,EACP,SAAS,GACV,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAGL,qBAAqB,EACrB,wBAAwB,EACxB,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,oBAAoB,EAAyB,MAAM,aAAa,CAAC;AAC1E,OAAO,EAIL,iBAAiB,EACjB,yBAAyB,EACzB,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAsJ9C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH;;;;GAIG;AACH,SAAS,oBAAoB,CAC3B,EAA6B;IAE7B,IAAI,CAAC,EAAE;QAAE,OAAO,SAAS,CAAC;IAC1B,OAAO;QACL,GAAG,CAAC,EAAE,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACzD,GAAG,CAAC,EAAE,CAAC,W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