@authfn/oauth-provider 0.0.0-stage → 0.1.1

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.
Files changed (54) hide show
  1. package/README.md +73 -2
  2. package/dist/authorize/index.d.ts +5 -0
  3. package/dist/authorize/index.d.ts.map +1 -0
  4. package/dist/authorize/index.js +247 -0
  5. package/dist/authorize/index.js.map +1 -0
  6. package/dist/http.d.ts +35 -0
  7. package/dist/http.d.ts.map +1 -0
  8. package/dist/http.js +161 -0
  9. package/dist/http.js.map +1 -0
  10. package/dist/index.d.ts +19 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +41 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/introspection/index.d.ts +13 -0
  15. package/dist/introspection/index.d.ts.map +1 -0
  16. package/dist/introspection/index.js +47 -0
  17. package/dist/introspection/index.js.map +1 -0
  18. package/dist/metadata/index.d.ts +10 -0
  19. package/dist/metadata/index.d.ts.map +1 -0
  20. package/dist/metadata/index.js +38 -0
  21. package/dist/metadata/index.js.map +1 -0
  22. package/dist/pkce.d.ts +4 -0
  23. package/dist/pkce.d.ts.map +1 -0
  24. package/dist/pkce.js +17 -0
  25. package/dist/pkce.js.map +1 -0
  26. package/dist/revocation/index.d.ts +12 -0
  27. package/dist/revocation/index.d.ts.map +1 -0
  28. package/dist/revocation/index.js +34 -0
  29. package/dist/revocation/index.js.map +1 -0
  30. package/dist/runtime.d.ts +57 -0
  31. package/dist/runtime.d.ts.map +1 -0
  32. package/dist/runtime.js +226 -0
  33. package/dist/runtime.js.map +1 -0
  34. package/dist/store.d.ts +155 -0
  35. package/dist/store.d.ts.map +1 -0
  36. package/dist/store.js +465 -0
  37. package/dist/store.js.map +1 -0
  38. package/dist/token/code.d.ts +11 -0
  39. package/dist/token/code.d.ts.map +1 -0
  40. package/dist/token/code.js +64 -0
  41. package/dist/token/code.js.map +1 -0
  42. package/dist/token/index.d.ts +5 -0
  43. package/dist/token/index.d.ts.map +1 -0
  44. package/dist/token/index.js +39 -0
  45. package/dist/token/index.js.map +1 -0
  46. package/dist/token/refresh.d.ts +10 -0
  47. package/dist/token/refresh.d.ts.map +1 -0
  48. package/dist/token/refresh.js +47 -0
  49. package/dist/token/refresh.js.map +1 -0
  50. package/dist/types.d.ts +177 -0
  51. package/dist/types.d.ts.map +1 -0
  52. package/dist/types.js +7 -0
  53. package/dist/types.js.map +1 -0
  54. package/package.json +41 -4
@@ -0,0 +1,155 @@
1
+ import { type AuthFnRuntimeConfig, type AuthFnSchemaDefinition } from 'authfn';
2
+ import { type OAuthAccessTokenInfo, type OAuthAuthorizationCodeRecord, type OAuthGrantRecord, type OAuthTokenKind, type OAuthTokenRecord } from './types.js';
3
+ /** Storage scope: the AuthFn database adapter and namespace (default `authfn`). */
4
+ export interface OAuthStore {
5
+ database: AuthFnRuntimeConfig['database'];
6
+ namespace?: string;
7
+ }
8
+ export declare function createOAuthProviderSchema(): AuthFnSchemaDefinition['schemas'];
9
+ export declare function createGrantWithCode(store: OAuthStore, input: {
10
+ clientId: string;
11
+ userId: string;
12
+ resource: string;
13
+ scopes: string[];
14
+ redirectUri: string;
15
+ codeChallenge: string;
16
+ now: Date;
17
+ }): Promise<{
18
+ grantId: string;
19
+ code: string;
20
+ }>;
21
+ export declare function findCode(store: OAuthStore, code: string): Promise<OAuthAuthorizationCodeRecord | null>;
22
+ /**
23
+ * Atomically marks a code consumed with `claimId`, which commits the tokens
24
+ * staged under it; false when another caller already did.
25
+ */
26
+ export declare function claimCode(store: OAuthStore, codeId: string, now: Date, claimId: string): Promise<boolean>;
27
+ export declare function findGrant(store: OAuthStore, grantId: string): Promise<OAuthGrantRecord | null>;
28
+ /**
29
+ * The grant, while it is unrevoked and its user still exists and is not
30
+ * disabled (the same owner rule API keys follow); null otherwise. This is the
31
+ * one grant rule: token issuance checks it before staging and again after its
32
+ * claim commits, and `activeTokenState` checks it at every use.
33
+ */
34
+ export declare function findLiveGrant(store: OAuthStore, grantId: string): Promise<OAuthGrantRecord | null>;
35
+ /**
36
+ * Revokes a grant. Every code, access token and refresh token issued under it
37
+ * stops working at once, because each validity check reads the grant.
38
+ */
39
+ export declare function revokeGrant(store: OAuthStore, grantId: string, reason: string, now: Date): Promise<boolean>;
40
+ export interface IssuedTokens {
41
+ accessToken: string;
42
+ refreshToken: string;
43
+ accessTokenExpiresIn: number;
44
+ scopes: string[];
45
+ }
46
+ /**
47
+ * Stages a one-hour access token for `scopes` and a 30-day refresh token for
48
+ * the full grant scope, in exchange for the code or refresh token `sourceId`.
49
+ * Both are written before the caller claims the source with the returned
50
+ * `claimId` (`claimCode`, `claimRefreshToken`), and neither is valid until
51
+ * that claim commits: the claim is the single commit point. A failure before
52
+ * it leaves the source unspent and the staged rows inert; a lost race leaves
53
+ * the loser's rows inert. If the response is lost after the claim, a retry is
54
+ * a replay, which revokes the grant (RFC 6749 4.1.2).
55
+ */
56
+ export declare function stageTokens(store: OAuthStore, grant: OAuthGrantRecord, scopes: string[], now: Date, sourceId: string): Promise<{
57
+ tokens: IssuedTokens;
58
+ claimId: string;
59
+ }>;
60
+ export declare function findToken(store: OAuthStore, token: string): Promise<OAuthTokenRecord | null>;
61
+ /**
62
+ * Atomically spends a refresh token with `claimId`, which commits the tokens
63
+ * staged under it; false when it was already rotated or revoked.
64
+ */
65
+ export declare function claimRefreshToken(store: OAuthStore, tokenId: string, now: Date, claimId: string): Promise<boolean>;
66
+ export declare function revokeToken(store: OAuthStore, tokenId: string, now: Date): Promise<void>;
67
+ /**
68
+ * The one validity rule for issued tokens: the token is of the expected
69
+ * kind, unexpired and unrevoked, the claim that issued it committed (its code
70
+ * or parent refresh token stores `issuingClaimId`), and its grant is live
71
+ * (`findLiveGrant`).
72
+ */
73
+ export declare function loadActiveToken(store: OAuthStore, token: string, kind: OAuthTokenKind, now: Date): Promise<{
74
+ record: OAuthTokenRecord;
75
+ grant: OAuthGrantRecord;
76
+ } | null>;
77
+ /** Applies the validity rule of `loadActiveToken` to a record already loaded. */
78
+ export declare function activeTokenState(store: OAuthStore, record: OAuthTokenRecord, kind: OAuthTokenKind, now: Date): Promise<{
79
+ record: OAuthTokenRecord;
80
+ grant: OAuthGrantRecord;
81
+ } | null>;
82
+ /** The user exists and is not disabled; shared with the API-key owner rule. */
83
+ export declare function isActiveUser(store: OAuthStore, userId: string): Promise<boolean>;
84
+ export declare function toAccessTokenInfo(record: OAuthTokenRecord): OAuthAccessTokenInfo;
85
+ /**
86
+ * Verifies an access token for a resource server in the same process. Returns
87
+ * `null` unless the token is active and was issued for exactly `resource`
88
+ * (its audience, RFC 8707). Pass the result to `requireScopes`.
89
+ */
90
+ export declare function verifyOAuthAccessToken(store: OAuthStore, token: string, options: {
91
+ resource: string;
92
+ now?: () => Date;
93
+ }): Promise<OAuthAccessTokenInfo | null>;
94
+ /** A user's authorization of one client at one resource. */
95
+ export interface OAuthTriple {
96
+ userId: string;
97
+ clientId: string;
98
+ resource: string;
99
+ }
100
+ /**
101
+ * Disconnects an app: the user's access for `clientId` at `resource`. The
102
+ * consent is removed, so even a trusted client shows the consent page again,
103
+ * and every live grant of that user, client and resource is revoked, with
104
+ * every code, access token and refresh token issued under them. Returns the
105
+ * number of grants revoked.
106
+ *
107
+ * The disconnect first writes a new generation for the triple. An
108
+ * authorization in progress reads the generation before it reads or records
109
+ * consent and again after it creates its grant; seeing it change, it revokes
110
+ * its grant and removes the consent it recorded. A grant created before the
111
+ * lookup below is revoked here; one created after it sees the change.
112
+ */
113
+ export declare function disconnectOAuthClient(store: OAuthStore, input: OAuthTriple & {
114
+ now?: () => Date;
115
+ }): Promise<number>;
116
+ /**
117
+ * Disconnects the app a grant belongs to, by grant ID (for example from a
118
+ * token's `grantId`). With `userId`, only that user's grant is accepted. Like
119
+ * `disconnectOAuthClient`, it revokes every live grant of the same user,
120
+ * client and resource, not only `grantId`, and removes the consent. Returns
121
+ * whether a live grant was revoked.
122
+ */
123
+ export declare function revokeOAuthGrant(store: OAuthStore, grantId: string, options?: {
124
+ userId?: string;
125
+ now?: () => Date;
126
+ }): Promise<boolean>;
127
+ /**
128
+ * The triple's disconnect generation, whatever the disconnect history: its
129
+ * disconnect row holds the value. Concurrent first disconnects can each add
130
+ * a row; the one with the lowest ID decides. Every value written is new and
131
+ * each disconnect overwrites every row, so a generation read before a
132
+ * disconnect never matches one read after it.
133
+ */
134
+ export declare function readGeneration(store: OAuthStore, triple: OAuthTriple): Promise<string>;
135
+ /**
136
+ * The scopes the user has approved for the triple since its latest disconnect
137
+ * (`generation`, from `readGeneration`): the union of those approvals, or
138
+ * null when there is none. An approval made before a disconnect never counts
139
+ * after it, even if it was written late.
140
+ */
141
+ export declare function findConsentScopes(store: OAuthStore, triple: OAuthTriple, generation: string): Promise<string[] | null>;
142
+ /**
143
+ * Records that the user approved `scopes` for the triple in `generation`;
144
+ * returns the approval's ID. The new row stores the union of the approvals it
145
+ * read, which it then deletes, so a generation keeps one row plus one per
146
+ * approval that ran concurrently. Concurrent approvals never overwrite each
147
+ * other: each only deletes rows written before it read them.
148
+ */
149
+ export declare function recordConsent(store: OAuthStore, input: OAuthTriple & {
150
+ scopes: string[];
151
+ generation: string;
152
+ now: Date;
153
+ }): Promise<string>;
154
+ export declare function deleteConsent(store: OAuthStore, consentId: string): Promise<void>;
155
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC5B,MAAM,QAAQ,CAAC;AAGhB,OAAO,EAIL,KAAK,oBAAoB,EACzB,KAAK,4BAA4B,EAEjC,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACtB,MAAM,YAAY,CAAC;AAEpB,mFAAmF;AACnF,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAC1C,SAAS,CAAC,EAAE,MAAM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,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAG5H;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,KAAK,EAAE,UAAU,EACjB,KAAK,EAAE,WAAW,GAAG;IAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,IAAI,CAAA;CAAE,GACvE,OAAO,CAAC,MAAM,CAAC,CASjB;AAED,wBAAsB,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEvF"}
package/dist/store.js ADDED
@@ -0,0 +1,465 @@
1
+ import { randomBytes } from 'node:crypto';
2
+ import { AUTHFN_LEGACY_USER_REFERENCE_MAX_LENGTH } from 'authfn';
3
+ import { findActiveApiKeyOwner } from 'authfn/core/api-keys';
4
+ import { hashSecret } from 'authfn/core/sessions';
5
+ import { OAUTH_ACCESS_TOKEN_TTL_SECONDS, OAUTH_AUTHORIZATION_CODE_TTL_SECONDS, OAUTH_REFRESH_TOKEN_TTL_SECONDS } from './types.js';
6
+ const MODELS = {
7
+ grants: 'oauth_provider_grants',
8
+ codes: 'oauth_provider_codes',
9
+ tokens: 'oauth_provider_tokens',
10
+ consents: 'oauth_provider_consents',
11
+ disconnects: 'oauth_provider_disconnects'
12
+ };
13
+ export function createOAuthProviderSchema() {
14
+ const id = { type: 'string', required: true, fieldName: 'id', maxLength: 255 };
15
+ const ref = (fieldName) => ({ type: 'string', required: true, fieldName, maxLength: 255 });
16
+ const text = (fieldName) => ({ type: 'string', required: true, fieldName });
17
+ const date = (fieldName, required = true) => ({ type: 'date', required, fieldName });
18
+ const scopes = { type: 'json', required: true, fieldName: 'scopes' };
19
+ // Written with every conditional claim and read back to decide its winner.
20
+ const claimId = { type: 'string', required: false, fieldName: 'claim_id', maxLength: 64 };
21
+ // Users created before AuthFn v2 may have IDs up to the legacy bound.
22
+ const userId = { ...ref('user_id'), maxLength: AUTHFN_LEGACY_USER_REFERENCE_MAX_LENGTH };
23
+ return [
24
+ {
25
+ modelName: MODELS.grants,
26
+ fields: {
27
+ id,
28
+ clientId: ref('client_id'),
29
+ userId,
30
+ resource: text('resource'),
31
+ scopes,
32
+ revokedAt: date('revoked_at', false),
33
+ revokedReason: { type: 'string', required: false, fieldName: 'revoked_reason', maxLength: 64 },
34
+ claimId,
35
+ createdAt: date('created_at'),
36
+ updatedAt: date('updated_at')
37
+ },
38
+ indexes: [{ name: 'idx_authfn_oauth_provider_grants_user_id', fields: ['userId'] }]
39
+ },
40
+ {
41
+ modelName: MODELS.codes,
42
+ fields: {
43
+ id,
44
+ codeHash: ref('code_hash'),
45
+ grantId: ref('grant_id'),
46
+ clientId: ref('client_id'),
47
+ userId,
48
+ resource: text('resource'),
49
+ scopes,
50
+ redirectUri: text('redirect_uri'),
51
+ codeChallenge: ref('code_challenge'),
52
+ expiresAt: date('expires_at'),
53
+ consumedAt: date('consumed_at', false),
54
+ claimId,
55
+ createdAt: date('created_at')
56
+ },
57
+ indexes: [{ name: 'idx_authfn_oauth_provider_codes_code_hash', fields: ['codeHash'], unique: true }]
58
+ },
59
+ {
60
+ modelName: MODELS.tokens,
61
+ fields: {
62
+ id,
63
+ kind: { type: 'string', required: true, fieldName: 'kind', maxLength: 16 },
64
+ tokenHash: ref('token_hash'),
65
+ grantId: ref('grant_id'),
66
+ clientId: ref('client_id'),
67
+ userId,
68
+ resource: text('resource'),
69
+ scopes,
70
+ expiresAt: date('expires_at'),
71
+ rotatedAt: date('rotated_at', false),
72
+ revokedAt: date('revoked_at', false),
73
+ claimId,
74
+ // The code or refresh token this token was issued for, and the claim
75
+ // that must have spent it: the token is valid only once it has.
76
+ sourceId: ref('source_id'),
77
+ issuingClaimId: { type: 'string', required: true, fieldName: 'issuing_claim_id', maxLength: 64 },
78
+ createdAt: date('created_at')
79
+ },
80
+ indexes: [
81
+ { name: 'idx_authfn_oauth_provider_tokens_token_hash', fields: ['tokenHash'], unique: true },
82
+ { name: 'idx_authfn_oauth_provider_tokens_grant_id', fields: ['grantId'] }
83
+ ]
84
+ },
85
+ {
86
+ modelName: MODELS.consents,
87
+ fields: {
88
+ id,
89
+ userId,
90
+ clientId: ref('client_id'),
91
+ resource: text('resource'),
92
+ scopes,
93
+ // The triple's disconnect generation when the user approved.
94
+ generation: { type: 'string', required: true, fieldName: 'generation', maxLength: 64 },
95
+ createdAt: date('created_at')
96
+ },
97
+ // A user's rows for one client and resource are few (see recordConsent);
98
+ // `resource` is unbounded text, so it cannot be part of a MySQL key.
99
+ indexes: [{ name: 'idx_authfn_oauth_provider_consents_user_id', fields: ['userId'] }]
100
+ },
101
+ {
102
+ modelName: MODELS.disconnects,
103
+ // Found by triple: one row, or a few after concurrent first disconnects
104
+ // (see readGeneration); each disconnect writes a fresh `generation`.
105
+ fields: {
106
+ id,
107
+ userId,
108
+ clientId: ref('client_id'),
109
+ resource: text('resource'),
110
+ generation: { type: 'string', required: true, fieldName: 'generation', maxLength: 64 },
111
+ createdAt: date('created_at'),
112
+ updatedAt: date('updated_at')
113
+ },
114
+ indexes: [{ name: 'idx_authfn_oauth_provider_disconnects_user_id', fields: ['userId'] }]
115
+ }
116
+ ];
117
+ }
118
+ function namespace(store) {
119
+ return store.namespace ?? 'authfn';
120
+ }
121
+ function createIdentifier(prefix) {
122
+ return `${prefix}_${randomBytes(12).toString('hex')}`;
123
+ }
124
+ function createSecret(prefix) {
125
+ return `${prefix}_${randomBytes(32).toString('base64url')}`;
126
+ }
127
+ function addSeconds(date, seconds) {
128
+ return new Date(date.getTime() + seconds * 1000);
129
+ }
130
+ function insert(store, model, data) {
131
+ return store.database.create({ model, data: data, namespace: namespace(store) });
132
+ }
133
+ function findBy(store, model, field, value) {
134
+ return store.database.findOne({ model, where: [{ field, operator: 'eq', value }], namespace: namespace(store) });
135
+ }
136
+ function whereId(id, unset = []) {
137
+ return [
138
+ { field: 'id', operator: 'eq', value: id },
139
+ ...unset.map((field) => ({ field, operator: 'eq', value: null }))
140
+ ];
141
+ }
142
+ const CODE_ID_PREFIX = 'oco';
143
+ /**
144
+ * Updates the row `id` only while every field in `unset` is still null, in one
145
+ * conditional statement that also writes `claimId`, then reads the row back:
146
+ * the caller whose claim ID is stored won. Exactly one concurrent caller wins;
147
+ * that is the single-use guarantee for codes and refresh tokens. The adapter's
148
+ * affected-row count is never consulted, because adapters do not all report
149
+ * it reliably. When the write throws, the read-back still decides: it may have
150
+ * committed before its acknowledgement was lost. A claim is never undone.
151
+ */
152
+ async function claimIfUnset(store, model, id, unset, data, claimId = createIdentifier('ocl')) {
153
+ let writeError;
154
+ try {
155
+ await store.database.updateMany({ model, where: whereId(id, unset), data: { ...data, claimId }, namespace: namespace(store) });
156
+ }
157
+ catch (error) {
158
+ writeError = { error };
159
+ }
160
+ const row = await findBy(store, model, 'id', id);
161
+ if (row?.claimId === claimId) {
162
+ return true;
163
+ }
164
+ // Unclaimed after a failed write: nothing happened, so report the failure.
165
+ if (writeError && !row?.claimId) {
166
+ throw writeError.error;
167
+ }
168
+ return false;
169
+ }
170
+ export async function createGrantWithCode(store, input) {
171
+ const { redirectUri, codeChallenge, now, ...shared } = input;
172
+ const grant = {
173
+ ...shared,
174
+ id: createIdentifier('ogr'),
175
+ revokedAt: null,
176
+ revokedReason: null,
177
+ createdAt: now,
178
+ updatedAt: now
179
+ };
180
+ await insert(store, MODELS.grants, grant);
181
+ const code = createSecret('oac');
182
+ const record = {
183
+ ...shared,
184
+ id: createIdentifier(CODE_ID_PREFIX),
185
+ codeHash: hashSecret(code),
186
+ grantId: grant.id,
187
+ redirectUri,
188
+ codeChallenge,
189
+ expiresAt: addSeconds(now, OAUTH_AUTHORIZATION_CODE_TTL_SECONDS),
190
+ consumedAt: null,
191
+ createdAt: now
192
+ };
193
+ await insert(store, MODELS.codes, record);
194
+ return { grantId: grant.id, code };
195
+ }
196
+ export function findCode(store, code) {
197
+ return findBy(store, MODELS.codes, 'codeHash', hashSecret(code));
198
+ }
199
+ /**
200
+ * Atomically marks a code consumed with `claimId`, which commits the tokens
201
+ * staged under it; false when another caller already did.
202
+ */
203
+ export function claimCode(store, codeId, now, claimId) {
204
+ return claimIfUnset(store, MODELS.codes, codeId, ['consumedAt'], { consumedAt: now }, claimId);
205
+ }
206
+ export function findGrant(store, grantId) {
207
+ return findBy(store, MODELS.grants, 'id', grantId);
208
+ }
209
+ /**
210
+ * The grant, while it is unrevoked and its user still exists and is not
211
+ * disabled (the same owner rule API keys follow); null otherwise. This is the
212
+ * one grant rule: token issuance checks it before staging and again after its
213
+ * claim commits, and `activeTokenState` checks it at every use.
214
+ */
215
+ export async function findLiveGrant(store, grantId) {
216
+ const grant = await findGrant(store, grantId);
217
+ return grant && !grant.revokedAt && (await isActiveUser(store, grant.userId)) ? grant : null;
218
+ }
219
+ /**
220
+ * Revokes a grant. Every code, access token and refresh token issued under it
221
+ * stops working at once, because each validity check reads the grant.
222
+ */
223
+ export async function revokeGrant(store, grantId, reason, now) {
224
+ const data = { revokedAt: now, revokedReason: reason, updatedAt: now };
225
+ return claimIfUnset(store, MODELS.grants, grantId, ['revokedAt'], data);
226
+ }
227
+ /**
228
+ * Stages a one-hour access token for `scopes` and a 30-day refresh token for
229
+ * the full grant scope, in exchange for the code or refresh token `sourceId`.
230
+ * Both are written before the caller claims the source with the returned
231
+ * `claimId` (`claimCode`, `claimRefreshToken`), and neither is valid until
232
+ * that claim commits: the claim is the single commit point. A failure before
233
+ * it leaves the source unspent and the staged rows inert; a lost race leaves
234
+ * the loser's rows inert. If the response is lost after the claim, a retry is
235
+ * a replay, which revokes the grant (RFC 6749 4.1.2).
236
+ */
237
+ export async function stageTokens(store, grant, scopes, now, sourceId) {
238
+ const accessToken = createSecret('oat');
239
+ const refreshToken = createSecret('ort');
240
+ const claimId = createIdentifier('ocl');
241
+ const base = {
242
+ grantId: grant.id,
243
+ clientId: grant.clientId,
244
+ userId: grant.userId,
245
+ resource: grant.resource,
246
+ rotatedAt: null,
247
+ revokedAt: null,
248
+ sourceId,
249
+ issuingClaimId: claimId,
250
+ createdAt: now
251
+ };
252
+ const access = {
253
+ ...base,
254
+ id: createIdentifier('otk'),
255
+ kind: 'access',
256
+ tokenHash: hashSecret(accessToken),
257
+ scopes,
258
+ expiresAt: addSeconds(now, OAUTH_ACCESS_TOKEN_TTL_SECONDS)
259
+ };
260
+ const refresh = {
261
+ ...base,
262
+ id: createIdentifier('otk'),
263
+ kind: 'refresh',
264
+ tokenHash: hashSecret(refreshToken),
265
+ scopes: grant.scopes,
266
+ expiresAt: addSeconds(now, OAUTH_REFRESH_TOKEN_TTL_SECONDS)
267
+ };
268
+ await insert(store, MODELS.tokens, access);
269
+ await insert(store, MODELS.tokens, refresh);
270
+ return { tokens: { accessToken, refreshToken, accessTokenExpiresIn: OAUTH_ACCESS_TOKEN_TTL_SECONDS, scopes }, claimId };
271
+ }
272
+ export function findToken(store, token) {
273
+ return findBy(store, MODELS.tokens, 'tokenHash', hashSecret(token));
274
+ }
275
+ /**
276
+ * Atomically spends a refresh token with `claimId`, which commits the tokens
277
+ * staged under it; false when it was already rotated or revoked.
278
+ */
279
+ export function claimRefreshToken(store, tokenId, now, claimId) {
280
+ return claimIfUnset(store, MODELS.tokens, tokenId, ['rotatedAt', 'revokedAt'], { rotatedAt: now }, claimId);
281
+ }
282
+ export async function revokeToken(store, tokenId, now) {
283
+ await store.database.updateMany({
284
+ model: MODELS.tokens,
285
+ where: whereId(tokenId, ['revokedAt']),
286
+ data: { revokedAt: now },
287
+ namespace: namespace(store)
288
+ });
289
+ }
290
+ /**
291
+ * The one validity rule for issued tokens: the token is of the expected
292
+ * kind, unexpired and unrevoked, the claim that issued it committed (its code
293
+ * or parent refresh token stores `issuingClaimId`), and its grant is live
294
+ * (`findLiveGrant`).
295
+ */
296
+ export async function loadActiveToken(store, token, kind, now) {
297
+ const record = await findToken(store, token);
298
+ return record ? activeTokenState(store, record, kind, now) : null;
299
+ }
300
+ /** Applies the validity rule of `loadActiveToken` to a record already loaded. */
301
+ export async function activeTokenState(store, record, kind, now) {
302
+ if (record.kind !== kind || record.revokedAt || record.expiresAt.getTime() <= now.getTime()) {
303
+ return null;
304
+ }
305
+ const sourceModel = record.sourceId.startsWith(`${CODE_ID_PREFIX}_`) ? MODELS.codes : MODELS.tokens;
306
+ const source = await findBy(store, sourceModel, 'id', record.sourceId);
307
+ if (!source?.claimId || source.claimId !== record.issuingClaimId) {
308
+ return null;
309
+ }
310
+ const grant = await findLiveGrant(store, record.grantId);
311
+ return grant ? { record, grant } : null;
312
+ }
313
+ /** The user exists and is not disabled; shared with the API-key owner rule. */
314
+ export async function isActiveUser(store, userId) {
315
+ return (await findActiveApiKeyOwner({ database: store.database, namespace: namespace(store) }, userId)) !== null;
316
+ }
317
+ export function toAccessTokenInfo(record) {
318
+ return {
319
+ tokenId: record.id,
320
+ grantId: record.grantId,
321
+ clientId: record.clientId,
322
+ userId: record.userId,
323
+ resource: record.resource,
324
+ scopes: [...record.scopes],
325
+ issuedAt: record.createdAt,
326
+ expiresAt: record.expiresAt
327
+ };
328
+ }
329
+ /**
330
+ * Verifies an access token for a resource server in the same process. Returns
331
+ * `null` unless the token is active and was issued for exactly `resource`
332
+ * (its audience, RFC 8707). Pass the result to `requireScopes`.
333
+ */
334
+ export async function verifyOAuthAccessToken(store, token, options) {
335
+ if (typeof token !== 'string' || token.length === 0 || typeof options?.resource !== 'string') {
336
+ return null;
337
+ }
338
+ const active = await loadActiveToken(store, token, 'access', options.now?.() ?? new Date());
339
+ return active && active.record.resource === options.resource ? toAccessTokenInfo(active.record) : null;
340
+ }
341
+ function whereTriple({ userId, clientId, resource }) {
342
+ return [
343
+ { field: 'userId', operator: 'eq', value: userId },
344
+ { field: 'clientId', operator: 'eq', value: clientId },
345
+ { field: 'resource', operator: 'eq', value: resource }
346
+ ];
347
+ }
348
+ /**
349
+ * Disconnects an app: the user's access for `clientId` at `resource`. The
350
+ * consent is removed, so even a trusted client shows the consent page again,
351
+ * and every live grant of that user, client and resource is revoked, with
352
+ * every code, access token and refresh token issued under them. Returns the
353
+ * number of grants revoked.
354
+ *
355
+ * The disconnect first writes a new generation for the triple. An
356
+ * authorization in progress reads the generation before it reads or records
357
+ * consent and again after it creates its grant; seeing it change, it revokes
358
+ * its grant and removes the consent it recorded. A grant created before the
359
+ * lookup below is revoked here; one created after it sees the change.
360
+ */
361
+ export async function disconnectOAuthClient(store, input) {
362
+ const { userId, clientId, resource } = input;
363
+ const triple = { userId, clientId, resource };
364
+ const now = input.now?.() ?? new Date();
365
+ await writeNewGeneration(store, triple, now);
366
+ // Consent goes before the grants: if revoking a grant then fails, a retry
367
+ // still finds the grant, while consent left behind would silently re-authorize.
368
+ await store.database.deleteMany({ model: MODELS.consents, where: whereTriple(triple), namespace: namespace(store) });
369
+ const grants = await store.database.findMany({
370
+ model: MODELS.grants,
371
+ where: whereTriple(triple),
372
+ namespace: namespace(store)
373
+ });
374
+ let revoked = 0;
375
+ for (const grant of grants) {
376
+ if (!grant.revokedAt && (await revokeGrant(store, grant.id, 'revoked', now))) {
377
+ revoked += 1;
378
+ }
379
+ }
380
+ return revoked;
381
+ }
382
+ /**
383
+ * Disconnects the app a grant belongs to, by grant ID (for example from a
384
+ * token's `grantId`). With `userId`, only that user's grant is accepted. Like
385
+ * `disconnectOAuthClient`, it revokes every live grant of the same user,
386
+ * client and resource, not only `grantId`, and removes the consent. Returns
387
+ * whether a live grant was revoked.
388
+ */
389
+ export async function revokeOAuthGrant(store, grantId, options) {
390
+ const grant = await findGrant(store, grantId);
391
+ if (!grant || (options?.userId !== undefined && grant.userId !== options.userId)) {
392
+ return false;
393
+ }
394
+ const { userId, clientId, resource } = grant;
395
+ return (await disconnectOAuthClient(store, { userId, clientId, resource, now: options?.now })) > 0;
396
+ }
397
+ /** The generation before the triple's first disconnect. */
398
+ const INITIAL_GENERATION = 'initial';
399
+ function findDisconnects(store, triple) {
400
+ return store.database.findMany({ model: MODELS.disconnects, where: whereTriple(triple), namespace: namespace(store) });
401
+ }
402
+ /**
403
+ * The triple's disconnect generation, whatever the disconnect history: its
404
+ * disconnect row holds the value. Concurrent first disconnects can each add
405
+ * a row; the one with the lowest ID decides. Every value written is new and
406
+ * each disconnect overwrites every row, so a generation read before a
407
+ * disconnect never matches one read after it.
408
+ */
409
+ export async function readGeneration(store, triple) {
410
+ const [first] = (await findDisconnects(store, triple)).sort((a, b) => (a.id < b.id ? -1 : 1));
411
+ return first?.generation ?? INITIAL_GENERATION;
412
+ }
413
+ async function writeNewGeneration(store, triple, now) {
414
+ if ((await findDisconnects(store, triple)).length === 0) {
415
+ const id = createIdentifier('odc');
416
+ await insert(store, MODELS.disconnects, { ...triple, id, generation: createIdentifier('ogn'), createdAt: now, updatedAt: now });
417
+ }
418
+ await store.database.updateMany({
419
+ model: MODELS.disconnects,
420
+ where: whereTriple(triple),
421
+ data: { generation: createIdentifier('ogn'), updatedAt: now },
422
+ namespace: namespace(store)
423
+ });
424
+ }
425
+ function findConsents(store, triple, generation) {
426
+ return store.database.findMany({
427
+ model: MODELS.consents,
428
+ where: [...whereTriple(triple), { field: 'generation', operator: 'eq', value: generation }],
429
+ namespace: namespace(store)
430
+ });
431
+ }
432
+ function unionScopes(records, scopes = []) {
433
+ return [...new Set([...records.flatMap((record) => record.scopes), ...scopes])];
434
+ }
435
+ /**
436
+ * The scopes the user has approved for the triple since its latest disconnect
437
+ * (`generation`, from `readGeneration`): the union of those approvals, or
438
+ * null when there is none. An approval made before a disconnect never counts
439
+ * after it, even if it was written late.
440
+ */
441
+ export async function findConsentScopes(store, triple, generation) {
442
+ const records = await findConsents(store, triple, generation);
443
+ return records.length === 0 ? null : unionScopes(records);
444
+ }
445
+ /**
446
+ * Records that the user approved `scopes` for the triple in `generation`;
447
+ * returns the approval's ID. The new row stores the union of the approvals it
448
+ * read, which it then deletes, so a generation keeps one row plus one per
449
+ * approval that ran concurrently. Concurrent approvals never overwrite each
450
+ * other: each only deletes rows written before it read them.
451
+ */
452
+ export async function recordConsent(store, input) {
453
+ const { now, scopes, ...consent } = input;
454
+ const earlier = await findConsents(store, consent, consent.generation);
455
+ const id = createIdentifier('ocs');
456
+ await insert(store, MODELS.consents, { ...consent, scopes: unionScopes(earlier, scopes), id, createdAt: now });
457
+ for (const record of earlier) {
458
+ await deleteConsent(store, record.id);
459
+ }
460
+ return id;
461
+ }
462
+ export async function deleteConsent(store, consentId) {
463
+ await store.database.deleteMany({ model: MODELS.consents, where: whereId(consentId), namespace: namespace(store) });
464
+ }
465
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EACL,uCAAuC,EAGxC,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EACL,8BAA8B,EAC9B,oCAAoC,EACpC,+BAA+B,EAOhC,MAAM,YAAY,CAAC;AAQpB,MAAM,MAAM,GAAG;IACb,MAAM,EAAE,uBAAuB;IAC/B,KAAK,EAAE,sBAAsB;IAC7B,MAAM,EAAE,uBAAuB;IAC/B,QAAQ,EAAE,yBAAyB;IACnC,WAAW,EAAE,4BAA4B;CACjC,CAAC;AAEX,MAAM,UAAU,yBAAyB;IACvC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAW,CAAC;IACxF,MAAM,GAAG,GAAG,CAAC,SAAiB,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,CAAU,CAAC;IAC5G,MAAM,IAAI,GAAG,CAAC,SAAiB,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