@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
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { hashSecret } from 'authfn/core/sessions';
|
|
3
|
+
const MODELS = {
|
|
4
|
+
clients: 'oauth_provider_clients',
|
|
5
|
+
documents: 'oauth_provider_document_clients',
|
|
6
|
+
events: 'oauth_provider_registration_events'
|
|
7
|
+
};
|
|
8
|
+
/** The `client_id` prefix of dynamically registered clients. */
|
|
9
|
+
export const REGISTERED_CLIENT_ID_PREFIX = 'ocd';
|
|
10
|
+
export function createRegistrationSchema() {
|
|
11
|
+
const id = { type: 'string', required: true, fieldName: 'id', maxLength: 255 };
|
|
12
|
+
const createdAt = { type: 'date', required: true, fieldName: 'created_at' };
|
|
13
|
+
return [
|
|
14
|
+
{
|
|
15
|
+
modelName: MODELS.clients,
|
|
16
|
+
fields: {
|
|
17
|
+
id,
|
|
18
|
+
name: { type: 'string', required: false, fieldName: 'name', maxLength: 255 },
|
|
19
|
+
redirectUris: { type: 'json', required: true, fieldName: 'redirect_uris' },
|
|
20
|
+
createdAt
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
// The last usable metadata document of each client_id URL, kept so a
|
|
25
|
+
// known client keeps working when a refetch is refused or fails.
|
|
26
|
+
modelName: MODELS.documents,
|
|
27
|
+
fields: {
|
|
28
|
+
id,
|
|
29
|
+
name: { type: 'string', required: false, fieldName: 'name', maxLength: 255 },
|
|
30
|
+
redirectUris: { type: 'json', required: true, fieldName: 'redirect_uris' },
|
|
31
|
+
fetchedAt: { type: 'date', required: true, fieldName: 'fetched_at' },
|
|
32
|
+
// `<claim time, 16-digit ms>:<random>` of the request allowed to refetch it.
|
|
33
|
+
claimId: { type: 'string', required: true, fieldName: 'claim_id', maxLength: 64 }
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
// One row per admitted registration or first fetch of an unknown
|
|
38
|
+
// metadata document client; rows older than the previous window are
|
|
39
|
+
// pruned as new ones arrive.
|
|
40
|
+
modelName: MODELS.events,
|
|
41
|
+
fields: {
|
|
42
|
+
id,
|
|
43
|
+
kind: { type: 'string', required: true, fieldName: 'kind', maxLength: 16 },
|
|
44
|
+
windowId: { type: 'string', required: true, fieldName: 'window_id', maxLength: 32 },
|
|
45
|
+
ipKey: { type: 'string', required: true, fieldName: 'ip_key', maxLength: 64 },
|
|
46
|
+
createdAt
|
|
47
|
+
},
|
|
48
|
+
indexes: [{ name: 'idx_authfn_oauth_provider_registration_events_window', fields: ['kind', 'windowId'] }]
|
|
49
|
+
}
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
function namespace(store) {
|
|
53
|
+
return store.namespace ?? 'authfn';
|
|
54
|
+
}
|
|
55
|
+
function createIdentifier(prefix) {
|
|
56
|
+
return `${prefix}_${randomBytes(12).toString('hex')}`;
|
|
57
|
+
}
|
|
58
|
+
const eq = (field, value) => ({ field, operator: 'eq', value });
|
|
59
|
+
export async function insertRegisteredClient(store, input) {
|
|
60
|
+
const record = {
|
|
61
|
+
id: createIdentifier(REGISTERED_CLIENT_ID_PREFIX),
|
|
62
|
+
name: input.name ?? null,
|
|
63
|
+
redirectUris: input.redirectUris,
|
|
64
|
+
createdAt: input.now
|
|
65
|
+
};
|
|
66
|
+
await store.database.create({ model: MODELS.clients, data: { ...record }, namespace: namespace(store) });
|
|
67
|
+
return record;
|
|
68
|
+
}
|
|
69
|
+
export function findRegisteredClient(store, clientId) {
|
|
70
|
+
return store.database.findOne({
|
|
71
|
+
model: MODELS.clients,
|
|
72
|
+
where: [eq('id', clientId)],
|
|
73
|
+
namespace: namespace(store)
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
export function findDocumentClient(store, clientId) {
|
|
77
|
+
return store.database.findOne({
|
|
78
|
+
model: MODELS.documents,
|
|
79
|
+
where: [eq('id', clientId)],
|
|
80
|
+
namespace: namespace(store)
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/** Zero-padded so that string order is time order in every adapter. */
|
|
84
|
+
function timeKey(ms) {
|
|
85
|
+
return String(Math.max(0, ms)).padStart(16, '0');
|
|
86
|
+
}
|
|
87
|
+
/** A refetch claim made at `now`, which sorts after every earlier claim. */
|
|
88
|
+
export function documentClaimId(now) {
|
|
89
|
+
return `${timeKey(now.getTime())}:${randomBytes(9).toString('hex')}`;
|
|
90
|
+
}
|
|
91
|
+
/** The time a refetch claim was made, in milliseconds. */
|
|
92
|
+
export function documentClaimTime(claimId) {
|
|
93
|
+
return Number(claimId.slice(0, 16));
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Stores a newly fetched document and returns the stored row: this one, or
|
|
97
|
+
* the row another request stored first from its own fetch, which is kept.
|
|
98
|
+
* Row counts are never trusted: not every adapter reports them.
|
|
99
|
+
*/
|
|
100
|
+
export async function createDocumentClient(store, record) {
|
|
101
|
+
try {
|
|
102
|
+
await store.database.create({ model: MODELS.documents, data: { ...record }, namespace: namespace(store) });
|
|
103
|
+
return record;
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
const stored = await findDocumentClient(store, record.id);
|
|
107
|
+
if (!stored) {
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
return stored;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Claims the refetch of a known client's document when no claim was made in
|
|
115
|
+
* the `intervalMs` before `now`, so that across every instance the document
|
|
116
|
+
* is refetched at most once per interval. The claim is a conditional update
|
|
117
|
+
* read back: the caller whose claim ID is stored won and gets that ID.
|
|
118
|
+
*/
|
|
119
|
+
export async function claimDocumentRefetch(store, clientId, now, intervalMs) {
|
|
120
|
+
const claimId = documentClaimId(now);
|
|
121
|
+
await store.database.updateMany({
|
|
122
|
+
model: MODELS.documents,
|
|
123
|
+
// Claim times up to now - interval sort before this bound; later ones after it.
|
|
124
|
+
where: [eq('id', clientId), { field: 'claimId', operator: 'lt', value: timeKey(now.getTime() - intervalMs + 1) }],
|
|
125
|
+
data: { claimId },
|
|
126
|
+
namespace: namespace(store)
|
|
127
|
+
});
|
|
128
|
+
return (await findDocumentClient(store, clientId))?.claimId === claimId ? claimId : undefined;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Applies the result of the refetch claimed as `claimId`: the fetched
|
|
132
|
+
* document, or `null` to drop the client. Only the current claim holder
|
|
133
|
+
* writes; a refetch whose claim was superseded (it stalled past the
|
|
134
|
+
* interval, or another instance's clock leads) changes nothing. Returns the
|
|
135
|
+
* row stored afterwards, read back since row counts are never trusted:
|
|
136
|
+
* this result when it applied, another claim's row, or `null` once dropped.
|
|
137
|
+
*/
|
|
138
|
+
export async function applyDocumentRefetch(store, clientId, claimId, document) {
|
|
139
|
+
const where = [eq('id', clientId), eq('claimId', claimId)];
|
|
140
|
+
await (document
|
|
141
|
+
? store.database.updateMany({ model: MODELS.documents, where, data: { ...document }, namespace: namespace(store) })
|
|
142
|
+
: store.database.deleteMany({ model: MODELS.documents, where, namespace: namespace(store) }));
|
|
143
|
+
return findDocumentClient(store, clientId);
|
|
144
|
+
}
|
|
145
|
+
/** No resolvable client IP: such events count only toward the global limit. */
|
|
146
|
+
const NO_IP = 'none';
|
|
147
|
+
/** Window ids are zero-padded so that string order is window order in every adapter. */
|
|
148
|
+
function windowIdOf(windowIndex) {
|
|
149
|
+
return String(windowIndex).padStart(16, '0');
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Admits one registration event of `kind` within fixed windows, or reports
|
|
153
|
+
* the seconds until the window ends. The event is stored first and the window
|
|
154
|
+
* counted after, so the event whose insert lands last sees every event
|
|
155
|
+
* admitted before it: concurrent callers never admit more than the limits,
|
|
156
|
+
* though at the boundary they can all refuse. A refused event is deleted, so
|
|
157
|
+
* refusals do not use up the window.
|
|
158
|
+
*/
|
|
159
|
+
export async function admitRegistrationEvent(store, input) {
|
|
160
|
+
const { kind, ip, now, limits } = input;
|
|
161
|
+
const windowMs = limits.windowSeconds * 1000;
|
|
162
|
+
const windowIndex = Math.floor(now.getTime() / windowMs);
|
|
163
|
+
const windowId = windowIdOf(windowIndex);
|
|
164
|
+
const ipKey = ip === undefined ? NO_IP : hashSecret(ip);
|
|
165
|
+
const id = createIdentifier('orv');
|
|
166
|
+
const scope = { namespace: namespace(store) };
|
|
167
|
+
await store.database.create({ model: MODELS.events, data: { id, kind, windowId, ipKey, createdAt: now }, ...scope });
|
|
168
|
+
// Reads at most limit + 1 rows instead of `count`, which not every adapter supports.
|
|
169
|
+
const exceeds = async (where, limit) => (await store.database.findMany({ model: MODELS.events, where, limit: limit + 1, ...scope })).length > limit;
|
|
170
|
+
const window = [eq('kind', kind), eq('windowId', windowId)];
|
|
171
|
+
const overGlobal = await exceeds(window, limits.global);
|
|
172
|
+
const overIp = !overGlobal && ip !== undefined && await exceeds([...window, eq('ipKey', ipKey)], limits.perIp);
|
|
173
|
+
if (overGlobal || overIp) {
|
|
174
|
+
await store.database.deleteMany({ model: MODELS.events, where: [eq('id', id)], ...scope });
|
|
175
|
+
return { admitted: false, retryAfterSeconds: Math.max(1, Math.ceil(((windowIndex + 1) * windowMs - now.getTime()) / 1000)) };
|
|
176
|
+
}
|
|
177
|
+
// Prune only windows before the previous one: a caller whose clock lags may
|
|
178
|
+
// still be counting the previous window, and one whose clock leads (or a
|
|
179
|
+
// request delayed across the rollover) a later one, which must stay intact.
|
|
180
|
+
await store.database.deleteMany({
|
|
181
|
+
model: MODELS.events,
|
|
182
|
+
where: [eq('kind', kind), { field: 'windowId', operator: 'lt', value: windowIdOf(windowIndex - 1) }],
|
|
183
|
+
...scope
|
|
184
|
+
});
|
|
185
|
+
return { admitted: true };
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/registration/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAOlD,MAAM,MAAM,GAAG;IACb,OAAO,EAAE,wBAAwB;IACjC,SAAS,EAAE,iCAAiC;IAC5C,MAAM,EAAE,oCAAoC;CACpC,CAAC;AAEX,gEAAgE;AAChE,MAAM,CAAC,MAAM,2BAA2B,GAAG,KAAK,CAAC;AAEjD,MAAM,UAAU,wBAAwB;IACtC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAW,CAAC;IACxF,MAAM,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,YAAY,EAAW,CAAC;IACrF,OAAO;QACL;YACE,SAAS,EAAE,MAAM,CAAC,OAAO;YACzB,MAAM,EAAE;gBACN,EAAE;gBACF,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,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AC,CAAC,GAAG,QAAQ,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC;IAC/H,CAAC;IACD,4EAA4E;IAC5E,yEAAyE;IACzE,4EAA4E;IAC5E,MAAM,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC;QAC9B,KAAK,EAAE,MAAM,CAAC,MAAM;QACpB,KAAK,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,CAAC,WAAW,GAAG,CAAC,CAAC,EAAE,CAAC;QACpG,GAAG,KAAK;KACT,CAAC,CAAC;IACH,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Route } from '@superfunctions/http';
|
|
2
|
+
import type { OAuthProviderRuntime } from '../runtime.js';
|
|
3
|
+
export declare const OAUTH_REVOCATION_PATH = "/oauth/revoke";
|
|
4
|
+
/**
|
|
5
|
+
* Token revocation (RFC 7009). Revoking a refresh token revokes its whole
|
|
6
|
+
* grant, including every access token issued under it (2.1); revoking an
|
|
7
|
+
* access token revokes only that token. An unknown token, or one issued to
|
|
8
|
+
* another client, is answered with 200 and left untouched (2.2), so the
|
|
9
|
+
* endpoint never reveals whether a token exists.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createRevocationRoute(runtime: OAuthProviderRuntime): Route;
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/revocation/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAGlD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAG1D,eAAO,MAAM,qBAAqB,kBAAkB,CAAC;AAErD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,oBAAoB,GAAG,KAAK,CAoB1E"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createAuthFnRouteMeta } from 'authfn/http/router';
|
|
2
|
+
import { authenticateClient, handleOAuth, requireParam, readFormBody } from '../http.js';
|
|
3
|
+
import { findToken, revokeGrant, revokeToken } from '../store.js';
|
|
4
|
+
export const OAUTH_REVOCATION_PATH = '/oauth/revoke';
|
|
5
|
+
/**
|
|
6
|
+
* Token revocation (RFC 7009). Revoking a refresh token revokes its whole
|
|
7
|
+
* grant, including every access token issued under it (2.1); revoking an
|
|
8
|
+
* access token revokes only that token. An unknown token, or one issued to
|
|
9
|
+
* another client, is answered with 200 and left untouched (2.2), so the
|
|
10
|
+
* endpoint never reveals whether a token exists.
|
|
11
|
+
*/
|
|
12
|
+
export function createRevocationRoute(runtime) {
|
|
13
|
+
return {
|
|
14
|
+
method: 'POST',
|
|
15
|
+
path: OAUTH_REVOCATION_PATH,
|
|
16
|
+
meta: createAuthFnRouteMeta('oauthRevoke', 'OAuth 2.0 token revocation', { mode: 'none' }),
|
|
17
|
+
handler: (request) => handleOAuth(async () => {
|
|
18
|
+
const params = await readFormBody(request);
|
|
19
|
+
const client = await authenticateClient(runtime, request, params);
|
|
20
|
+
const record = await findToken(runtime.store, requireParam(params, 'token'));
|
|
21
|
+
if (record?.clientId === client.clientId) {
|
|
22
|
+
const now = runtime.now();
|
|
23
|
+
if (record.kind === 'refresh') {
|
|
24
|
+
await revokeGrant(runtime.store, record.grantId, 'revoked', now);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
await revokeToken(runtime.store, record.id, now);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return new Response(null, { status: 200, headers: { 'cache-control': 'no-store' } });
|
|
31
|
+
})
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=index.js.map
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BACN,MAAM,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;gBACnD,CAAC;YACH,CAAC;YACD,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,eAAe,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC;QACvF,CAAC,CAAC;KACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { AuthFnPluginRuntimeContext, AuthFnRuntimeConfig } from 'authfn';
|
|
2
|
+
import type { OAuthProviderClient, OAuthProviderPluginRuntimeConfig, OAuthProviderResource } from './types.js';
|
|
3
|
+
export declare const OAUTH_PROVIDER_PLUGIN_NAME = "oauthProvider";
|
|
4
|
+
/** Shared state every endpoint reads: validated config, lookups and storage scope. */
|
|
5
|
+
export interface OAuthProviderRuntime {
|
|
6
|
+
ctx: AuthFnPluginRuntimeContext;
|
|
7
|
+
config: OAuthProviderPluginRuntimeConfig;
|
|
8
|
+
store: {
|
|
9
|
+
database: AuthFnRuntimeConfig['database'];
|
|
10
|
+
namespace: string;
|
|
11
|
+
};
|
|
12
|
+
now(): Date;
|
|
13
|
+
findClient(clientId: string): OAuthProviderClient | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* A configured client, or one that registered itself (see
|
|
16
|
+
* `withClientRegistration`). `request` identifies the caller for the
|
|
17
|
+
* registration rate limit; it can throw a `temporarily_unavailable` OAuthError.
|
|
18
|
+
*/
|
|
19
|
+
resolveClient(clientId: string, request: Request): Promise<OAuthProviderClient | undefined>;
|
|
20
|
+
findResource(resource: string): OAuthProviderResource | undefined;
|
|
21
|
+
}
|
|
22
|
+
export declare function createOAuthProviderRuntime(ctx: AuthFnPluginRuntimeContext): OAuthProviderRuntime;
|
|
23
|
+
/**
|
|
24
|
+
* Reads and validates `pluginRuntime.oauthProvider`. Runs when the server is
|
|
25
|
+
* created, so a misconfigured provider fails at startup with
|
|
26
|
+
* `AUTHFN_CONFIG_INVALID` rather than on the first authorization.
|
|
27
|
+
*/
|
|
28
|
+
export declare function readOAuthProviderRuntimeConfig(config: AuthFnRuntimeConfig): OAuthProviderPluginRuntimeConfig;
|
|
29
|
+
/**
|
|
30
|
+
* A redirect URI that keeps the authorization response off plaintext
|
|
31
|
+
* networks and out of the browser's own schemes (OAuth 2.1 2.3.1, RFC 8252
|
|
32
|
+
* 7), written in visible ASCII: `https`, `http` only to a loopback IP literal, or a native app's
|
|
33
|
+
* reverse-domain private-use scheme. Every other scheme (`javascript`,
|
|
34
|
+
* `data`, `file`, `ws`, a dotless custom scheme, ...) is rejected. Its query
|
|
35
|
+
* must not use a response parameter name, which the response would otherwise
|
|
36
|
+
* duplicate.
|
|
37
|
+
*/
|
|
38
|
+
export declare function isAllowedRedirectUri(value: unknown): value is string;
|
|
39
|
+
export declare function isAbsoluteUriWithoutFragment(value: unknown): value is string;
|
|
40
|
+
/**
|
|
41
|
+
* Exact redirect URI matching (OAuth 2.1), except that an `http` loopback IP
|
|
42
|
+
* redirect URI matches on any port (RFC 8252 7.3).
|
|
43
|
+
*/
|
|
44
|
+
export declare function matchesRedirectUri(client: OAuthProviderClient, redirectUri: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Resolves the requested scopes for a resource (RFC 6749 3.3). An absent
|
|
47
|
+
* `scope` asks for every scope the resource offers. Each requested scope must
|
|
48
|
+
* be one the resource offers, compared exactly.
|
|
49
|
+
*/
|
|
50
|
+
export declare function resolveRequestedScopes(resource: OAuthProviderResource, scope: string | undefined): string[];
|
|
51
|
+
/** Resolves the single resource (RFC 8707) a request is bound to. */
|
|
52
|
+
export declare function requireResource(runtime: OAuthProviderRuntime, value: string | undefined): OAuthProviderResource;
|
|
53
|
+
export interface OAuthEndpoints {
|
|
54
|
+
issuer: string;
|
|
55
|
+
authorization: string;
|
|
56
|
+
token: string;
|
|
57
|
+
revocation: string;
|
|
58
|
+
introspection: string;
|
|
59
|
+
registration: string;
|
|
60
|
+
}
|
|
61
|
+
/** Removes trailing slashes in linear time. */
|
|
62
|
+
export declare function trimTrailingSlashes(value: string): string;
|
|
63
|
+
export declare function resolveEndpoints(runtime: OAuthProviderRuntime, request: Request): Promise<OAuthEndpoints>;
|
|
64
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAM9E,OAAO,KAAK,EACV,mBAAmB,EACnB,gCAAgC,EAChC,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,0BAA0B,kBAAkB,CAAC;AAE1D,sFAAsF;AACtF,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,0BAA0B,CAAC;IAChC,MAAM,EAAE,gCAAgC,CAAC;IACzC,KAAK,EAAE;QAAE,QAAQ,EAAE,mBAAmB,CAAC,UAAU,CAAC,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IACxE,GAAG,IAAI,IAAI,CAAC;IACZ,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,mBAAmB,GAAG,SAAS,CAAC;IAC9D;;;;OAIG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC,CAAC;IAC5F,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS,CAAC;CACnE;AAED,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,0BAA0B,GAAG,oBAAoB,CAahG;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,mBAAmB,GAAG,gCAAgC,CAmB5G;AA0ED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CASpE;AAgBD,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAS5E;AAGD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAgB5F;AAYD;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,CAa3G;AAED,qEAAqE;AACrE,wBAAgB,eAAe,CAAC,OAAO,EAAE,oBAAoB,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,qBAAqB,CAS/G;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,+CAA+C;AAC/C,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMzD;AAED,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,oBAAoB,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,cAAc,CAAC,CAW/G"}
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { AuthFnConfigError } from 'authfn/core/errors';
|
|
2
|
+
import { readPluginRuntimeConfig } from 'authfn/core/plugin-runtime';
|
|
3
|
+
import { resolveEnvironment } from 'authfn/core/environment';
|
|
4
|
+
import { assertRegisteredScopes } from 'authfn/core/scopes';
|
|
5
|
+
import { isBearerCredential, OAuthError } from './http.js';
|
|
6
|
+
export const OAUTH_PROVIDER_PLUGIN_NAME = 'oauthProvider';
|
|
7
|
+
export function createOAuthProviderRuntime(ctx) {
|
|
8
|
+
const config = readOAuthProviderRuntimeConfig(ctx.config);
|
|
9
|
+
const clients = new Map(config.clients.map((client) => [client.clientId, client]));
|
|
10
|
+
const resources = new Map(config.resources.map((resource) => [resource.resource, resource]));
|
|
11
|
+
return {
|
|
12
|
+
ctx,
|
|
13
|
+
config,
|
|
14
|
+
store: { database: ctx.config.database, namespace: ctx.namespace },
|
|
15
|
+
now: () => config.now?.() ?? new Date(),
|
|
16
|
+
findClient: (clientId) => clients.get(clientId),
|
|
17
|
+
resolveClient: async (clientId) => clients.get(clientId),
|
|
18
|
+
findResource: (resource) => resources.get(resource)
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Reads and validates `pluginRuntime.oauthProvider`. Runs when the server is
|
|
23
|
+
* created, so a misconfigured provider fails at startup with
|
|
24
|
+
* `AUTHFN_CONFIG_INVALID` rather than on the first authorization.
|
|
25
|
+
*/
|
|
26
|
+
export function readOAuthProviderRuntimeConfig(config) {
|
|
27
|
+
const runtime = readPluginRuntimeConfig(config, OAUTH_PROVIDER_PLUGIN_NAME);
|
|
28
|
+
if (typeof runtime.loginRequired !== 'function' || typeof runtime.consent !== 'function') {
|
|
29
|
+
throw configError('pluginRuntime.oauthProvider needs loginRequired and consent hooks');
|
|
30
|
+
}
|
|
31
|
+
if (!Array.isArray(runtime.clients) || !Array.isArray(runtime.resources) || runtime.resources.length === 0) {
|
|
32
|
+
throw configError('pluginRuntime.oauthProvider needs clients and at least one resource');
|
|
33
|
+
}
|
|
34
|
+
const clientIds = new Set();
|
|
35
|
+
for (const client of runtime.clients) {
|
|
36
|
+
validateClient(client, clientIds);
|
|
37
|
+
}
|
|
38
|
+
const resourceIds = new Set();
|
|
39
|
+
const introspectionSecrets = new Set();
|
|
40
|
+
for (const resource of runtime.resources) {
|
|
41
|
+
validateResource(config, resource, resourceIds, introspectionSecrets);
|
|
42
|
+
}
|
|
43
|
+
return runtime;
|
|
44
|
+
}
|
|
45
|
+
function validateClient(client, clientIds) {
|
|
46
|
+
if (typeof client?.clientId !== 'string' || client.clientId.length === 0 || clientIds.has(client.clientId)) {
|
|
47
|
+
throw configError('Each OAuth client needs a unique clientId');
|
|
48
|
+
}
|
|
49
|
+
clientIds.add(client.clientId);
|
|
50
|
+
if (!Array.isArray(client.redirectUris) || client.redirectUris.length === 0 ||
|
|
51
|
+
!client.redirectUris.every(isAllowedRedirectUri)) {
|
|
52
|
+
throw configError(`OAuth client ${client.clientId} needs absolute redirect URIs without a fragment, using https, an http ` +
|
|
53
|
+
'loopback IP or a reverse-domain native app scheme, whose query has no OAuth response parameter');
|
|
54
|
+
}
|
|
55
|
+
const method = client.tokenEndpointAuthMethod;
|
|
56
|
+
if (method !== undefined && !['none', 'client_secret_basic', 'client_secret_post'].includes(method)) {
|
|
57
|
+
throw configError(`OAuth client ${client.clientId} has an unsupported token endpoint auth method`);
|
|
58
|
+
}
|
|
59
|
+
if ((method === 'none' && client.clientSecret) || (method && method !== 'none' && !client.clientSecret)) {
|
|
60
|
+
throw configError(`OAuth client ${client.clientId} auth method and clientSecret disagree`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function validateResource(config, resource, resourceIds, introspectionSecrets) {
|
|
64
|
+
if (!isAbsoluteUriWithoutFragment(resource?.resource) || resourceIds.has(resource.resource)) {
|
|
65
|
+
throw configError('Each OAuth resource must be a unique absolute URI without a fragment');
|
|
66
|
+
}
|
|
67
|
+
resourceIds.add(resource.resource);
|
|
68
|
+
// Introspection identifies the calling resource server by its secret, so
|
|
69
|
+
// a shared secret would make one resource answer for another's audience.
|
|
70
|
+
// The secret is sent as a Bearer credential, so it must fit that grammar.
|
|
71
|
+
const secret = resource.introspectionSecret;
|
|
72
|
+
if (secret !== undefined) {
|
|
73
|
+
if (typeof secret !== 'string' || !isBearerCredential(secret) || introspectionSecrets.has(secret)) {
|
|
74
|
+
throw configError(`OAuth resource ${resource.resource} needs a unique Bearer-token introspectionSecret`);
|
|
75
|
+
}
|
|
76
|
+
introspectionSecrets.add(secret);
|
|
77
|
+
}
|
|
78
|
+
if (!Array.isArray(resource.scopes) || resource.scopes.length === 0) {
|
|
79
|
+
throw configError(`OAuth resource ${resource.resource} needs at least one scope`);
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
assertRegisteredScopes(config.scopes, resource.scopes);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
throw configError(`OAuth resource ${resource.resource} scopes must be grantable by the AuthFn scope registry`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const LOOPBACK_HOSTS = new Set(['127.0.0.1', '[::1]']);
|
|
89
|
+
/** Parameters the authorization response adds to the redirect URI. */
|
|
90
|
+
const RESPONSE_PARAMETERS = ['code', 'state', 'iss', 'error', 'error_description', 'error_uri'];
|
|
91
|
+
/**
|
|
92
|
+
* Only visible ASCII (RFC 3986 URIs, with non-ASCII hosts in punycode and
|
|
93
|
+
* other characters percent-encoded): the redirect URI is sent as is in the
|
|
94
|
+
* `Location` header, which carries no spaces, controls or raw Unicode.
|
|
95
|
+
*/
|
|
96
|
+
function isVisibleAscii(value) {
|
|
97
|
+
return /^[\x21-\x7e]+$/.test(value);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* A private-use URI scheme in reverse domain name form (RFC 8252 7.1), such
|
|
101
|
+
* as `com.example.app:`. The dot is outside both character classes, so
|
|
102
|
+
* matching is linear.
|
|
103
|
+
*/
|
|
104
|
+
const PRIVATE_USE_SCHEME = /^[a-z][a-z0-9+-]*(?:\.[a-z0-9+-]+)+:$/;
|
|
105
|
+
/**
|
|
106
|
+
* A redirect URI that keeps the authorization response off plaintext
|
|
107
|
+
* networks and out of the browser's own schemes (OAuth 2.1 2.3.1, RFC 8252
|
|
108
|
+
* 7), written in visible ASCII: `https`, `http` only to a loopback IP literal, or a native app's
|
|
109
|
+
* reverse-domain private-use scheme. Every other scheme (`javascript`,
|
|
110
|
+
* `data`, `file`, `ws`, a dotless custom scheme, ...) is rejected. Its query
|
|
111
|
+
* must not use a response parameter name, which the response would otherwise
|
|
112
|
+
* duplicate.
|
|
113
|
+
*/
|
|
114
|
+
export function isAllowedRedirectUri(value) {
|
|
115
|
+
if (!isAbsoluteUriWithoutFragment(value) || !isVisibleAscii(value)) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
const url = new URL(value);
|
|
119
|
+
const allowedScheme = url.protocol === 'https:' ? startsWithOrigin(value, url)
|
|
120
|
+
: url.protocol === 'http:' ? LOOPBACK_HOSTS.has(url.hostname) && startsWithOrigin(value, url)
|
|
121
|
+
: PRIVATE_USE_SCHEME.test(url.protocol);
|
|
122
|
+
return allowedScheme && RESPONSE_PARAMETERS.every((name) => !url.searchParams.has(name));
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The raw value begins with its own origin, `scheme://host[:port]`. The
|
|
126
|
+
* redirect is sent as written, and a browser resolves forms the URL parser
|
|
127
|
+
* repairs (`https:host/cb`, `https:/host/cb`, backslashes, userinfo)
|
|
128
|
+
* differently or relative to the authorization page.
|
|
129
|
+
*/
|
|
130
|
+
function startsWithOrigin(value, url) {
|
|
131
|
+
return value.slice(0, url.origin.length).toLowerCase() === url.origin.toLowerCase();
|
|
132
|
+
}
|
|
133
|
+
function configError(message) {
|
|
134
|
+
return new AuthFnConfigError(message);
|
|
135
|
+
}
|
|
136
|
+
export function isAbsoluteUriWithoutFragment(value) {
|
|
137
|
+
if (typeof value !== 'string' || value.includes('#')) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
try {
|
|
141
|
+
return Boolean(new URL(value));
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Exact redirect URI matching (OAuth 2.1), except that an `http` loopback IP
|
|
149
|
+
* redirect URI matches on any port (RFC 8252 7.3).
|
|
150
|
+
*/
|
|
151
|
+
export function matchesRedirectUri(client, redirectUri) {
|
|
152
|
+
// The URL parser drops tabs and newlines, so check the raw value first.
|
|
153
|
+
if (!isVisibleAscii(redirectUri)) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
if (client.redirectUris.includes(redirectUri)) {
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
const requested = parseLoopback(redirectUri);
|
|
160
|
+
return requested !== null && client.redirectUris.some((registered) => {
|
|
161
|
+
const candidate = parseLoopback(registered);
|
|
162
|
+
return candidate !== null &&
|
|
163
|
+
candidate.hostname === requested.hostname &&
|
|
164
|
+
candidate.pathname === requested.pathname &&
|
|
165
|
+
candidate.search === requested.search;
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
function parseLoopback(value) {
|
|
169
|
+
try {
|
|
170
|
+
const url = new URL(value);
|
|
171
|
+
return url.protocol === 'http:' && LOOPBACK_HOSTS.has(url.hostname) && !value.includes('#') &&
|
|
172
|
+
startsWithOrigin(value, url) ? url : null;
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Resolves the requested scopes for a resource (RFC 6749 3.3). An absent
|
|
180
|
+
* `scope` asks for every scope the resource offers. Each requested scope must
|
|
181
|
+
* be one the resource offers, compared exactly.
|
|
182
|
+
*/
|
|
183
|
+
export function resolveRequestedScopes(resource, scope) {
|
|
184
|
+
if (scope === undefined) {
|
|
185
|
+
return [...resource.scopes];
|
|
186
|
+
}
|
|
187
|
+
const requested = scope.split(' ');
|
|
188
|
+
if (requested.some((entry) => entry.length === 0)) {
|
|
189
|
+
throw new OAuthError('invalid_scope', 'Scope must be space-delimited scope tokens');
|
|
190
|
+
}
|
|
191
|
+
const unknown = requested.filter((entry) => !resource.scopes.includes(entry));
|
|
192
|
+
if (unknown.length > 0) {
|
|
193
|
+
throw new OAuthError('invalid_scope', `Scope is not available for this resource: ${unknown.join(' ')}`);
|
|
194
|
+
}
|
|
195
|
+
return [...new Set(requested)];
|
|
196
|
+
}
|
|
197
|
+
/** Resolves the single resource (RFC 8707) a request is bound to. */
|
|
198
|
+
export function requireResource(runtime, value) {
|
|
199
|
+
if (!value) {
|
|
200
|
+
throw new OAuthError('invalid_target', 'Parameter resource is required');
|
|
201
|
+
}
|
|
202
|
+
const resource = runtime.findResource(value);
|
|
203
|
+
if (!resource) {
|
|
204
|
+
throw new OAuthError('invalid_target', 'Resource is not served by this authorization server');
|
|
205
|
+
}
|
|
206
|
+
return resource;
|
|
207
|
+
}
|
|
208
|
+
/** Removes trailing slashes in linear time. */
|
|
209
|
+
export function trimTrailingSlashes(value) {
|
|
210
|
+
let end = value.length;
|
|
211
|
+
while (end > 0 && value.charCodeAt(end - 1) === 47) {
|
|
212
|
+
end -= 1;
|
|
213
|
+
}
|
|
214
|
+
return value.slice(0, end);
|
|
215
|
+
}
|
|
216
|
+
export async function resolveEndpoints(runtime, request) {
|
|
217
|
+
const environment = await resolveEnvironment(runtime.ctx.config, request);
|
|
218
|
+
const base = `${trimTrailingSlashes(environment.baseUrl)}${trimTrailingSlashes(runtime.ctx.basePath)}/oauth`;
|
|
219
|
+
return {
|
|
220
|
+
issuer: environment.issuer,
|
|
221
|
+
authorization: `${base}/authorize`,
|
|
222
|
+
token: `${base}/token`,
|
|
223
|
+
revocation: `${base}/revoke`,
|
|
224
|
+
introspection: `${base}/introspect`,
|
|
225
|
+
registration: `${base}/register`
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7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