@fluixi/oauth2 1.0.0-alpha.11 → 1.0.0-alpha.111
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
package/dist/callback.cjs
CHANGED
|
@@ -26,10 +26,10 @@ __export(callback_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(callback_exports);
|
|
27
27
|
var import_core = require("@fluixi/core");
|
|
28
28
|
var import_signal2 = require("@fluixi/reactive/signal");
|
|
29
|
-
var import_di2 = require("@fluixi/
|
|
29
|
+
var import_di2 = require("@fluixi/di");
|
|
30
30
|
|
|
31
31
|
// src/tokens.ts
|
|
32
|
-
var import_di = require("@fluixi/
|
|
32
|
+
var import_di = require("@fluixi/di");
|
|
33
33
|
var AuthServiceToken = (0, import_di.injectionToken)("AuthService");
|
|
34
34
|
var AuthClientToken = (0, import_di.injectionToken)("AuthClient");
|
|
35
35
|
|
package/dist/callback.d.ts
CHANGED
|
@@ -66,7 +66,7 @@ export interface CallbackState {
|
|
|
66
66
|
*
|
|
67
67
|
* return (
|
|
68
68
|
* <main>
|
|
69
|
-
* <Show when={error} fallback={<p>Signing you in
|
|
69
|
+
* <Show when={error} fallback={<p>Signing you in...</p>}>
|
|
70
70
|
* <h1>Could not sign you in</h1>
|
|
71
71
|
* <p>{error}</p>
|
|
72
72
|
* <a href="/login">Try again</a>
|
|
@@ -97,7 +97,7 @@ export interface OAuthCallbackProps extends OAuthCallbackOptions {
|
|
|
97
97
|
* import { OAuthCallback } from '@fluixi/oauth2/callback';
|
|
98
98
|
*
|
|
99
99
|
* export default OAuthCallback({
|
|
100
|
-
* pending: () => <p>Signing you in
|
|
100
|
+
* pending: () => <p>Signing you in...</p>,
|
|
101
101
|
* failed: (reason) => (
|
|
102
102
|
* <>
|
|
103
103
|
* <h1>Could not sign you in</h1>
|
package/dist/callback.js
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
*/
|
|
24
24
|
import { onMount } from '@fluixi/core';
|
|
25
25
|
import { signal } from '@fluixi/reactive/signal';
|
|
26
|
-
import { inject } from '@fluixi/
|
|
26
|
+
import { inject } from '@fluixi/di';
|
|
27
27
|
import { AuthServiceToken } from './tokens.js';
|
|
28
28
|
import { paramsFromUrl } from './service.js';
|
|
29
29
|
/** The message for a failure, preferring the provider's own words. */
|
|
@@ -58,7 +58,7 @@ const spent = new Set();
|
|
|
58
58
|
*
|
|
59
59
|
* return (
|
|
60
60
|
* <main>
|
|
61
|
-
* <Show when={error} fallback={<p>Signing you in
|
|
61
|
+
* <Show when={error} fallback={<p>Signing you in...</p>}>
|
|
62
62
|
* <h1>Could not sign you in</h1>
|
|
63
63
|
* <p>{error}</p>
|
|
64
64
|
* <a href="/login">Try again</a>
|
|
@@ -158,7 +158,7 @@ export function useOAuthCallback(options = {}) {
|
|
|
158
158
|
* import { OAuthCallback } from '@fluixi/oauth2/callback';
|
|
159
159
|
*
|
|
160
160
|
* export default OAuthCallback({
|
|
161
|
-
* pending: () => <p>Signing you in
|
|
161
|
+
* pending: () => <p>Signing you in...</p>,
|
|
162
162
|
* failed: (reason) => (
|
|
163
163
|
* <>
|
|
164
164
|
* <h1>Could not sign you in</h1>
|
package/dist/callback.mjs
CHANGED
|
@@ -1,32 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
paramsFromUrl
|
|
3
|
+
} from "./chunk-2GLWT7XH.mjs";
|
|
4
|
+
import "./chunk-4QRYJ4TN.mjs";
|
|
5
|
+
import "./chunk-5WX3EV2W.mjs";
|
|
6
|
+
import {
|
|
7
|
+
AuthServiceToken
|
|
8
|
+
} from "./chunk-MHWZTXZZ.mjs";
|
|
9
|
+
import "./chunk-AWVECOG7.mjs";
|
|
10
|
+
import "./chunk-QC2FFASM.mjs";
|
|
11
|
+
import "./chunk-VCNXQCIH.mjs";
|
|
12
|
+
import "./chunk-SJOBQPG6.mjs";
|
|
13
|
+
import "./chunk-AAN3YN4S.mjs";
|
|
14
|
+
import "./chunk-XQJTQV3C.mjs";
|
|
15
|
+
import "./chunk-27BGFJIY.mjs";
|
|
16
|
+
import "./chunk-AXPSPTNP.mjs";
|
|
1
17
|
import "./chunk-7P6ASYW6.mjs";
|
|
2
18
|
|
|
3
19
|
// src/callback.ts
|
|
4
20
|
import { onMount } from "@fluixi/core";
|
|
5
21
|
import { signal } from "@fluixi/reactive/signal";
|
|
6
|
-
import { inject } from "@fluixi/
|
|
7
|
-
|
|
8
|
-
// src/tokens.ts
|
|
9
|
-
import { injectionToken } from "@fluixi/start/di";
|
|
10
|
-
var AuthServiceToken = injectionToken("AuthService");
|
|
11
|
-
var AuthClientToken = injectionToken("AuthClient");
|
|
12
|
-
|
|
13
|
-
// src/service.ts
|
|
14
|
-
import { markReactiveScope, openReactiveScope, withReactiveScope } from "@fluixi/reactive/signal";
|
|
15
|
-
import { createSession } from "@fluixi/session";
|
|
16
|
-
import { createAuthHooks } from "@fluixi/auth/client";
|
|
17
|
-
function paramsFromUrl(url) {
|
|
18
|
-
const href = url ?? (typeof location === "undefined" ? null : location.href);
|
|
19
|
-
if (!href) return {};
|
|
20
|
-
const { searchParams } = new URL(String(href));
|
|
21
|
-
return {
|
|
22
|
-
code: searchParams.get("code") ?? void 0,
|
|
23
|
-
state: searchParams.get("state") ?? void 0,
|
|
24
|
-
error: searchParams.get("error") ?? void 0,
|
|
25
|
-
errorDescription: searchParams.get("error_description") ?? void 0
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// src/callback.ts
|
|
22
|
+
import { inject } from "@fluixi/di";
|
|
30
23
|
function reasonFor(cause) {
|
|
31
24
|
if (cause instanceof Error) return cause.message;
|
|
32
25
|
return String(cause);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
OAuthError
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-7P6ASYW6.mjs";
|
|
3
|
+
} from "./chunk-AXPSPTNP.mjs";
|
|
5
4
|
|
|
6
5
|
// src/dpop.ts
|
|
7
6
|
async function loadJose() {
|
|
@@ -87,13 +86,14 @@ function boundKeyOf(claims) {
|
|
|
87
86
|
const cnf = claims.cnf;
|
|
88
87
|
return typeof cnf?.jkt === "string" ? cnf.jkt : null;
|
|
89
88
|
}
|
|
89
|
+
|
|
90
90
|
export {
|
|
91
|
-
boundKeyOf,
|
|
92
91
|
createDpopKey,
|
|
93
92
|
exportDpopKey,
|
|
94
93
|
importDpopKey,
|
|
95
|
-
nonceFrom,
|
|
96
|
-
proofFor,
|
|
97
94
|
thumbprintOf,
|
|
98
|
-
|
|
95
|
+
proofFor,
|
|
96
|
+
nonceFrom,
|
|
97
|
+
wantsNonce,
|
|
98
|
+
boundKeyOf
|
|
99
99
|
};
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import {
|
|
2
|
+
COOKIE_SESSION,
|
|
3
|
+
createServerClient
|
|
4
|
+
} from "./chunk-4QRYJ4TN.mjs";
|
|
5
|
+
import {
|
|
6
|
+
watchProviderSession
|
|
7
|
+
} from "./chunk-5WX3EV2W.mjs";
|
|
8
|
+
import {
|
|
9
|
+
createBrowserClient
|
|
10
|
+
} from "./chunk-AWVECOG7.mjs";
|
|
11
|
+
import {
|
|
12
|
+
expiryFromJwt
|
|
13
|
+
} from "./chunk-QC2FFASM.mjs";
|
|
14
|
+
import {
|
|
15
|
+
safeReturnTo
|
|
16
|
+
} from "./chunk-VCNXQCIH.mjs";
|
|
17
|
+
import {
|
|
18
|
+
OAuthError
|
|
19
|
+
} from "./chunk-AXPSPTNP.mjs";
|
|
20
|
+
|
|
21
|
+
// src/service.ts
|
|
22
|
+
import { createSignal, markReactiveScope, openReactiveScope, withReactiveScope } from "@fluixi/reactive/signal";
|
|
23
|
+
import { createSession } from "@fluixi/session";
|
|
24
|
+
import { createAuthHooks } from "@fluixi/auth/client";
|
|
25
|
+
function paramsFromUrl(url) {
|
|
26
|
+
const href = url ?? (typeof location === "undefined" ? null : location.href);
|
|
27
|
+
if (!href) return {};
|
|
28
|
+
const { searchParams } = new URL(String(href));
|
|
29
|
+
return {
|
|
30
|
+
code: searchParams.get("code") ?? void 0,
|
|
31
|
+
state: searchParams.get("state") ?? void 0,
|
|
32
|
+
error: searchParams.get("error") ?? void 0,
|
|
33
|
+
errorDescription: searchParams.get("error_description") ?? void 0
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function clientFor(options) {
|
|
37
|
+
if (options.client) return options.client;
|
|
38
|
+
return options.config.tokens === "server" ? createServerClient(options.config) : createBrowserClient(options.config);
|
|
39
|
+
}
|
|
40
|
+
function createAuthService(options) {
|
|
41
|
+
const tokens = options.config.tokens;
|
|
42
|
+
const scope = openReactiveScope({ kind: "service", name: "AuthService", ...tokens ? { detail: `tokens: ${tokens}` } : {} });
|
|
43
|
+
const service = withReactiveScope(scope, () => buildAuthService(options));
|
|
44
|
+
markReactiveScope(service, scope);
|
|
45
|
+
return service;
|
|
46
|
+
}
|
|
47
|
+
function buildAuthService(options) {
|
|
48
|
+
const client = clientFor(options);
|
|
49
|
+
let latest = null;
|
|
50
|
+
const fetchUserFor = async (token) => {
|
|
51
|
+
if (options.fetchUser) return options.fetchUser(token);
|
|
52
|
+
return client.fetchUser(token === COOKIE_SESSION ? void 0 : token);
|
|
53
|
+
};
|
|
54
|
+
const resumesFromCookie = options.config.tokens === "server" && typeof window !== "undefined";
|
|
55
|
+
const [ready, setReady] = createSignal(!resumesFromCookie);
|
|
56
|
+
const session = createSession({
|
|
57
|
+
/** The credential is the callback, so this is the code exchange. */
|
|
58
|
+
async login(params) {
|
|
59
|
+
latest = await client.handleCallback(params);
|
|
60
|
+
return { token: latest.accessToken, expiresAt: latest.expiresAt };
|
|
61
|
+
},
|
|
62
|
+
fetchUser: fetchUserFor,
|
|
63
|
+
async refresh() {
|
|
64
|
+
latest = await client.refresh();
|
|
65
|
+
return { token: latest.accessToken, expiresAt: latest.expiresAt };
|
|
66
|
+
},
|
|
67
|
+
async logout() {
|
|
68
|
+
latest = null;
|
|
69
|
+
await client.logout();
|
|
70
|
+
},
|
|
71
|
+
getExpiry(token) {
|
|
72
|
+
if (token === COOKIE_SESSION) return null;
|
|
73
|
+
return latest?.expiresAt ?? expiryFromJwt(token);
|
|
74
|
+
},
|
|
75
|
+
access: options.access,
|
|
76
|
+
storageKeys: options.storageKeys,
|
|
77
|
+
refreshSkewMs: options.refreshSkewMs,
|
|
78
|
+
onLogin: options.onLogin,
|
|
79
|
+
onLogout: options.onLogout,
|
|
80
|
+
onExpired: options.onExpired,
|
|
81
|
+
onError: options.onError
|
|
82
|
+
});
|
|
83
|
+
const hooks = createAuthHooks({
|
|
84
|
+
session,
|
|
85
|
+
ready,
|
|
86
|
+
navigate: options.navigate,
|
|
87
|
+
loginPath: options.loginPath ?? "/login",
|
|
88
|
+
homePath: options.homePath ?? "/",
|
|
89
|
+
forbiddenPath: options.forbiddenPath ?? "/403"
|
|
90
|
+
});
|
|
91
|
+
if (resumesFromCookie && options.config.tokens === "server" && options.config.watchSession !== false) {
|
|
92
|
+
watchProviderSession({ basePath: options.config.basePath });
|
|
93
|
+
}
|
|
94
|
+
const renderedSignedOut = hooks.store.seeded && hooks.store.value().user == null;
|
|
95
|
+
if (resumesFromCookie && renderedSignedOut) setReady(true);
|
|
96
|
+
else if (resumesFromCookie) {
|
|
97
|
+
void (async () => {
|
|
98
|
+
try {
|
|
99
|
+
await session.adopt(COOKIE_SESSION, await fetchUserFor(COOKIE_SESSION));
|
|
100
|
+
} catch {
|
|
101
|
+
} finally {
|
|
102
|
+
setReady(true);
|
|
103
|
+
}
|
|
104
|
+
})();
|
|
105
|
+
}
|
|
106
|
+
return Object.assign(session, {
|
|
107
|
+
client,
|
|
108
|
+
protectedRoute: hooks.protectedRoute,
|
|
109
|
+
Can: hooks.Can,
|
|
110
|
+
Protect: hooks.Protect,
|
|
111
|
+
useAuth: hooks.useAuth,
|
|
112
|
+
useUser: hooks.useUser,
|
|
113
|
+
useCan: hooks.useCan,
|
|
114
|
+
signIn(loginOptions = {}) {
|
|
115
|
+
return client.login(loginOptions);
|
|
116
|
+
},
|
|
117
|
+
/**
|
|
118
|
+
* Finish a login and say where to go.
|
|
119
|
+
*
|
|
120
|
+
* The destination is checked before it is handed back, so an app that navigates to it
|
|
121
|
+
* without looking cannot be turned into an open redirect by a poisoned login link.
|
|
122
|
+
*/
|
|
123
|
+
async complete(params) {
|
|
124
|
+
const callback = params ?? paramsFromUrl();
|
|
125
|
+
if (!callback.code && !callback.error) {
|
|
126
|
+
throw new OAuthError(
|
|
127
|
+
"complete() found no callback parameters. It runs in the browser, on the redirect URI, where the code and the PKCE verifier both are.",
|
|
128
|
+
"no_callback_params"
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
await session.login(callback);
|
|
132
|
+
return safeReturnTo(client.consumeReturnTo?.(), {
|
|
133
|
+
fallback: "/",
|
|
134
|
+
allowedOrigins: "allowedReturnOrigins" in options.config ? options.config.allowedReturnOrigins : void 0
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export {
|
|
141
|
+
paramsFromUrl,
|
|
142
|
+
createAuthService
|
|
143
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AuthClientToken,
|
|
3
|
+
AuthServiceToken
|
|
4
|
+
} from "./chunk-MHWZTXZZ.mjs";
|
|
5
|
+
|
|
6
|
+
// src/module.ts
|
|
7
|
+
import { defineModule } from "@fluixi/start/app";
|
|
8
|
+
function authModule(auth) {
|
|
9
|
+
return defineModule({
|
|
10
|
+
name: "oauth2",
|
|
11
|
+
providers: [
|
|
12
|
+
// One instance for every request on the server. It holds no per-visitor state there:
|
|
13
|
+
// the signed-in user comes from request locals, which `sessionLocals` fills per request.
|
|
14
|
+
{ provide: AuthServiceToken, useValue: auth },
|
|
15
|
+
{ provide: AuthClientToken, useValue: auth.client }
|
|
16
|
+
]
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
authModule
|
|
22
|
+
};
|