@fluixi/oauth2 1.0.0-alpha.11 → 1.0.0-alpha.110
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/dist/api-guard.cjs +8 -3
- package/dist/api-guard.mjs +9 -135
- package/dist/backchannel.cjs +467 -0
- package/dist/backchannel.d.ts +39 -0
- package/dist/backchannel.d.ts.map +1 -0
- package/dist/backchannel.js +97 -0
- package/dist/backchannel.mjs +19 -0
- package/dist/browser.cjs +6 -1
- package/dist/browser.mjs +10 -702
- package/dist/callback.cjs +2 -2
- package/dist/callback.d.ts +2 -2
- package/dist/callback.js +3 -3
- package/dist/callback.mjs +17 -24
- package/dist/{dpop-YPGCGL7S.mjs → chunk-27BGFJIY.mjs} +6 -6
- package/dist/chunk-2GLWT7XH.mjs +143 -0
- package/dist/chunk-3EICMAF7.mjs +22 -0
- package/dist/chunk-4OHJTTX7.mjs +398 -0
- package/dist/chunk-4QRYJ4TN.mjs +86 -0
- package/dist/chunk-5WX3EV2W.mjs +78 -0
- package/dist/chunk-7AMC336S.mjs +52 -0
- package/dist/chunk-AAN3YN4S.mjs +63 -0
- package/dist/chunk-AWVECOG7.mjs +404 -0
- package/dist/chunk-GN5SERAQ.mjs +189 -0
- package/dist/chunk-KIXTZEEW.mjs +80 -0
- package/dist/chunk-KVW2S6VY.mjs +36 -0
- package/dist/chunk-MHWZTXZZ.mjs +9 -0
- package/dist/chunk-QC2FFASM.mjs +67 -0
- package/dist/chunk-SJOBQPG6.mjs +77 -0
- package/dist/chunk-VCNXQCIH.mjs +26 -0
- package/dist/chunk-XQJTQV3C.mjs +91 -0
- package/dist/client-auth.mjs +6 -78
- package/dist/discovery.cjs +6 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +6 -1
- package/dist/discovery.mjs +6 -59
- package/dist/dpop-store.mjs +6 -118
- package/dist/dpop.mjs +11 -95
- package/dist/env-config.cjs +1 -1
- package/dist/env-config.mjs +5 -214
- package/dist/env-credentials.mjs +5 -47
- package/dist/index.cjs +108 -8
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.mjs +50 -912
- package/dist/module.cjs +1 -1
- package/dist/module.mjs +5 -20
- package/dist/pkce.mjs +11 -56
- package/dist/presets.cjs +1 -1
- package/dist/presets.mjs +5 -214
- package/dist/return-to.mjs +4 -22
- package/dist/roles.cjs +1 -1
- package/dist/roles.d.ts +1 -1
- package/dist/roles.js +1 -1
- package/dist/roles.mjs +4 -32
- package/dist/server-client.mjs +7 -107
- package/dist/server.cjs +795 -153
- package/dist/server.d.ts +85 -4
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +577 -75
- package/dist/server.mjs +442 -310
- package/dist/service-client.cjs +7 -2
- package/dist/service-client.mjs +16 -133
- package/dist/service.cjs +104 -5
- package/dist/service.d.ts +1 -1
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +38 -6
- package/dist/service.mjs +14 -879
- package/dist/session-monitor.cjs +98 -0
- package/dist/session-monitor.d.ts +32 -0
- package/dist/session-monitor.d.ts.map +1 -0
- package/dist/session-monitor.js +104 -0
- package/dist/session-monitor.mjs +7 -0
- package/dist/tokens.cjs +1 -1
- package/dist/tokens.d.ts +2 -2
- package/dist/tokens.d.ts.map +1 -1
- package/dist/tokens.js +1 -1
- package/dist/tokens.mjs +5 -4
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.mjs +4 -9
- package/dist/verify.cjs +15 -5
- package/dist/verify.d.ts +2 -2
- package/dist/verify.js +2 -2
- package/dist/verify.mjs +17 -580
- package/package.json +23 -17
- package/dist/browser-N432SMC3.mjs +0 -3545
- package/dist/chunk-4TPZVJSR.mjs +0 -10
- package/dist/chunk-ZVDC3JW7.mjs +0 -15
- package/dist/dpop-DYUR2CH2.mjs +0 -100
- /package/dist/{chunk-OGSFNTKA.mjs → chunk-AXPSPTNP.mjs} +0 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenID Connect Back-Channel Logout, the app's half: the provider posts a logout token when a
|
|
3
|
+
* session this app took part in ends, and the app ends its own session for it.
|
|
4
|
+
*
|
|
5
|
+
* Logouts are kept in a `LogoutStore`. The default holds them in this process's memory, which
|
|
6
|
+
* is right for one instance; several instances behind a balancer each need to hear of every
|
|
7
|
+
* logout, so they share a store (Redis, a table) passed as `logouts`.
|
|
8
|
+
*/
|
|
9
|
+
import { createTokenVerifier } from './verify.js';
|
|
10
|
+
export const LOGOUT_EVENT = 'http://schemas.openid.net/event/backchannel-logout';
|
|
11
|
+
/** Logouts in memory, forgotten after `ttlMs` (a session that old has expired anyway). */
|
|
12
|
+
export function memoryLogouts(ttlMs = 14 * 24 * 3600_000) {
|
|
13
|
+
const sids = new Map();
|
|
14
|
+
const subs = new Map();
|
|
15
|
+
const prune = (now) => {
|
|
16
|
+
for (const map of [sids, subs])
|
|
17
|
+
for (const [key, at] of map)
|
|
18
|
+
if (now - at > ttlMs)
|
|
19
|
+
map.delete(key);
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
add(entry) {
|
|
23
|
+
prune(Date.now());
|
|
24
|
+
if (entry.sid)
|
|
25
|
+
sids.set(entry.sid, entry.at);
|
|
26
|
+
else if (entry.sub)
|
|
27
|
+
subs.set(entry.sub, Math.max(entry.at, subs.get(entry.sub) ?? 0));
|
|
28
|
+
},
|
|
29
|
+
ended(session) {
|
|
30
|
+
if (session.sid && sids.has(session.sid))
|
|
31
|
+
return true;
|
|
32
|
+
const all = session.sub ? subs.get(session.sub) : undefined;
|
|
33
|
+
return all !== undefined && session.since <= all;
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** The claims of an ID token, unverified: it came from the token endpoint and sits in a sealed cookie. */
|
|
38
|
+
export function idTokenClaims(idToken) {
|
|
39
|
+
if (!idToken)
|
|
40
|
+
return {};
|
|
41
|
+
try {
|
|
42
|
+
const part = idToken.split('.')[1] ?? '';
|
|
43
|
+
const json = atob(part.replace(/-/g, '+').replace(/_/g, '/').padEnd(Math.ceil(part.length / 4) * 4, '='));
|
|
44
|
+
const claims = JSON.parse(json);
|
|
45
|
+
return {
|
|
46
|
+
sid: typeof claims.sid === 'string' ? claims.sid : undefined,
|
|
47
|
+
sub: typeof claims.sub === 'string' ? claims.sub : undefined,
|
|
48
|
+
iat: typeof claims.iat === 'number' ? claims.iat : undefined,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return {};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function headerOf(token) {
|
|
56
|
+
try {
|
|
57
|
+
const part = token.split('.')[0] ?? '';
|
|
58
|
+
return JSON.parse(atob(part.replace(/-/g, '+').replace(/_/g, '/').padEnd(Math.ceil(part.length / 4) * 4, '=')));
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return {};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Checks a logout token as the specification asks: signature, issuer, audience and age like
|
|
66
|
+
* any token, then the logout event, a `sid` or a `sub`, and no `nonce` (which only an ID token
|
|
67
|
+
* carries, so a token with one is an ID token being passed off as a logout).
|
|
68
|
+
*/
|
|
69
|
+
export function logoutTokenVerifier(options) {
|
|
70
|
+
const verify = createTokenVerifier({
|
|
71
|
+
issuer: options.issuer,
|
|
72
|
+
audience: options.clientId,
|
|
73
|
+
jwksUri: options.jwksUri,
|
|
74
|
+
jwks: options.jwks,
|
|
75
|
+
require: (claims) => {
|
|
76
|
+
const events = claims.events;
|
|
77
|
+
if (!events || typeof events !== 'object' || !(LOGOUT_EVENT in events))
|
|
78
|
+
return 'no logout event';
|
|
79
|
+
if ('nonce' in claims)
|
|
80
|
+
return 'a logout token has no nonce';
|
|
81
|
+
if (typeof claims.sid !== 'string' && typeof claims.sub !== 'string')
|
|
82
|
+
return 'names no session and no subject';
|
|
83
|
+
return true;
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
return async (token) => {
|
|
87
|
+
const typ = headerOf(token).typ;
|
|
88
|
+
if (typ !== undefined && typ !== 'logout+jwt')
|
|
89
|
+
throw new Error('not a logout token');
|
|
90
|
+
const claims = await verify(token);
|
|
91
|
+
return {
|
|
92
|
+
sid: typeof claims.sid === 'string' ? claims.sid : undefined,
|
|
93
|
+
sub: typeof claims.sub === 'string' ? claims.sub : undefined,
|
|
94
|
+
at: (typeof claims.iat === 'number' ? claims.iat : Math.floor(Date.now() / 1000)) * 1000,
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LOGOUT_EVENT,
|
|
3
|
+
idTokenClaims,
|
|
4
|
+
logoutTokenVerifier,
|
|
5
|
+
memoryLogouts
|
|
6
|
+
} from "./chunk-KIXTZEEW.mjs";
|
|
7
|
+
import "./chunk-4OHJTTX7.mjs";
|
|
8
|
+
import "./chunk-7AMC336S.mjs";
|
|
9
|
+
import "./chunk-KVW2S6VY.mjs";
|
|
10
|
+
import "./chunk-SJOBQPG6.mjs";
|
|
11
|
+
import "./chunk-AAN3YN4S.mjs";
|
|
12
|
+
import "./chunk-AXPSPTNP.mjs";
|
|
13
|
+
import "./chunk-7P6ASYW6.mjs";
|
|
14
|
+
export {
|
|
15
|
+
LOGOUT_EVENT,
|
|
16
|
+
idTokenClaims,
|
|
17
|
+
logoutTokenVerifier,
|
|
18
|
+
memoryLogouts
|
|
19
|
+
};
|
package/dist/browser.cjs
CHANGED
|
@@ -307,8 +307,12 @@ async function discover(issuer, fetcher = fetch) {
|
|
|
307
307
|
try {
|
|
308
308
|
response = await fetcher(documentUrl(issuer));
|
|
309
309
|
} catch (cause) {
|
|
310
|
+
const why = cause instanceof Error ? cause.message : String(cause);
|
|
310
311
|
throw new OAuthError(
|
|
311
|
-
|
|
312
|
+
typeof window === "undefined" ? (
|
|
313
|
+
// On a server nothing blocks the read: the provider is down, or the address is wrong.
|
|
314
|
+
`Could not reach the provider at ${documentUrl(issuer)}: is it running, and is the issuer right? (${why})`
|
|
315
|
+
) : `Could not read the discovery document at ${documentUrl(issuer)}. In a browser this is usually the provider refusing a cross-origin read: give \`endpoints\` directly, or resolve them on a server. (${why})`,
|
|
312
316
|
"discovery_unreachable"
|
|
313
317
|
);
|
|
314
318
|
}
|
|
@@ -333,6 +337,7 @@ async function discover(issuer, fetcher = fetch) {
|
|
|
333
337
|
jwks: doc.jwks_uri,
|
|
334
338
|
introspection: doc.introspection_endpoint,
|
|
335
339
|
revocation: doc.revocation_endpoint,
|
|
340
|
+
checkSession: doc.check_session_iframe,
|
|
336
341
|
issuer: doc.issuer ?? issuer
|
|
337
342
|
};
|
|
338
343
|
})();
|