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