@oatscenter/trellis 0.100.0-rc.14 → 0.100.0-rc.15
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/native/discovery.js
CHANGED
|
@@ -27,25 +27,35 @@ const metadataSchema = z.object({
|
|
|
27
27
|
.min(1),
|
|
28
28
|
}),
|
|
29
29
|
});
|
|
30
|
+
/** RFC 9728 protected resource metadata, as the Console's address serves it. */
|
|
31
|
+
const resourceSchema = z.object({
|
|
32
|
+
resource: z.string(),
|
|
33
|
+
authorization_servers: z.tuple([z.string()]),
|
|
34
|
+
});
|
|
35
|
+
/**
|
|
36
|
+
* The issuer an HTTPS address names (HTTP only for literal loopback hosts).
|
|
37
|
+
* A development installation's issuer carries a path (`/auth`) on the
|
|
38
|
+
* Console's origin; metadata lives under the issuer either way.
|
|
39
|
+
*/
|
|
40
|
+
function issuerOf(address) {
|
|
41
|
+
const url = new URL(address);
|
|
42
|
+
const host = url.hostname.replace(/^\[|\]$/g, "");
|
|
43
|
+
const loopback = host === "localhost" ||
|
|
44
|
+
host === "::1" ||
|
|
45
|
+
(isIP(host) === 4 && host.startsWith("127."));
|
|
46
|
+
if (url.username ||
|
|
47
|
+
url.password ||
|
|
48
|
+
url.search ||
|
|
49
|
+
url.hash ||
|
|
50
|
+
(url.protocol !== "https:" && !(url.protocol === "http:" && loopback)))
|
|
51
|
+
throw new AuthError({ reason: "InvalidIssuer" });
|
|
52
|
+
return `${url.origin}${url.pathname.replace(/\/+$/, "")}`;
|
|
53
|
+
}
|
|
30
54
|
/** Decode a bounded OAuth response before interpreting its protocol fields. @internal */
|
|
31
55
|
/** Discover only the selected HTTPS origin (literal loopback HTTP is allowed), without redirects. Retained custody never repins from discovery. */
|
|
32
56
|
export async function discoverNativeOAuth(origin, options = {}) {
|
|
33
57
|
try {
|
|
34
|
-
const
|
|
35
|
-
const host = url.hostname.replace(/^\[|\]$/g, "");
|
|
36
|
-
const loopback = host === "localhost" ||
|
|
37
|
-
host === "::1" ||
|
|
38
|
-
(isIP(host) === 4 && host.startsWith("127."));
|
|
39
|
-
if (url.username ||
|
|
40
|
-
url.password ||
|
|
41
|
-
url.search ||
|
|
42
|
-
url.hash ||
|
|
43
|
-
(url.protocol !== "https:" && !(url.protocol === "http:" && loopback)))
|
|
44
|
-
throw new AuthError({ reason: "InvalidIssuer" });
|
|
45
|
-
// A development installation's issuer carries a path (`/auth`) on the
|
|
46
|
-
// Console's origin; metadata lives under the issuer either way.
|
|
47
|
-
const issuer = `${url.origin}${url.pathname.replace(/\/+$/, "")}`;
|
|
48
|
-
const response = await fetch(`${issuer}/.well-known/oauth-authorization-server`, {
|
|
58
|
+
const get = (url) => fetch(url, {
|
|
49
59
|
redirect: "error",
|
|
50
60
|
credentials: "omit",
|
|
51
61
|
signal: AbortSignal.any([
|
|
@@ -53,10 +63,27 @@ export async function discoverNativeOAuth(origin, options = {}) {
|
|
|
53
63
|
...(options.signal ? [options.signal] : []),
|
|
54
64
|
]),
|
|
55
65
|
});
|
|
66
|
+
let issuer = issuerOf(origin);
|
|
67
|
+
let response = await get(`${issuer}/.well-known/oauth-authorization-server`);
|
|
56
68
|
if (response.status === 429)
|
|
57
69
|
throw new AuthError({ reason: "OAuthBusy" });
|
|
58
|
-
if (!response.ok
|
|
59
|
-
|
|
70
|
+
if (!response.ok ||
|
|
71
|
+
!response.headers.get("Content-Type")?.startsWith("application/json")) {
|
|
72
|
+
// The Console's address names its sign-in in protected resource
|
|
73
|
+
// metadata (RFC 9728), so people can log in with the address they use.
|
|
74
|
+
const named = await get(`${issuer}/.well-known/oauth-protected-resource`);
|
|
75
|
+
if (!named.ok)
|
|
76
|
+
throw new AuthError({ reason: "OAuthUnavailable" });
|
|
77
|
+
const resource = resourceSchema.parse(await boundedJson(named));
|
|
78
|
+
if (issuerOf(resource.resource) !== issuer)
|
|
79
|
+
throw new AuthError({ reason: "InvalidIssuer" });
|
|
80
|
+
issuer = issuerOf(resource.authorization_servers[0]);
|
|
81
|
+
response = await get(`${issuer}/.well-known/oauth-authorization-server`);
|
|
82
|
+
if (response.status === 429)
|
|
83
|
+
throw new AuthError({ reason: "OAuthBusy" });
|
|
84
|
+
if (!response.ok)
|
|
85
|
+
throw new AuthError({ reason: "OAuthUnavailable" });
|
|
86
|
+
}
|
|
60
87
|
const dpopNonce = usableNonce(response.headers.get("DPoP-Nonce"));
|
|
61
88
|
const metadata = metadataSchema.parse(await boundedJson(response));
|
|
62
89
|
if (metadata.issuer !== issuer)
|
package/package.json
CHANGED
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@nats-io/obj": "^3.4.0",
|
|
52
52
|
"@nats-io/transport-node": "^3.4.0",
|
|
53
53
|
"@noble/hashes": "1.8.0",
|
|
54
|
-
"@oatscenter/result": "0.100.0-rc.
|
|
54
|
+
"@oatscenter/result": "0.100.0-rc.15",
|
|
55
55
|
"@opentelemetry/api": "^1.9.1",
|
|
56
56
|
"@opentelemetry/context-async-hooks": "~2.11.0",
|
|
57
57
|
"@opentelemetry/core": "~2.11.0",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"uqr": "0.1.3",
|
|
71
71
|
"zod": "^4.3.6"
|
|
72
72
|
},
|
|
73
|
-
"version": "0.100.0-rc.
|
|
73
|
+
"version": "0.100.0-rc.15",
|
|
74
74
|
"type": "module",
|
|
75
75
|
"license": "Apache-2.0",
|
|
76
76
|
"publishConfig": {
|