@capybara-hq/plugin-sdk 0.1.0-rc.51 → 0.1.0-rc.52
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/agent-docs/connector-templates.md +3 -0
- package/dist/connector-auth.d.ts +8 -0
- package/dist/connector-auth.js +68 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -43,6 +43,9 @@ Fields of `template`:
|
|
|
43
43
|
tenant id). List only what really differs per org.
|
|
44
44
|
- `auth`: the auth method without credentials: `none`, `bearer`, `basic`, `api_key`, `headers`,
|
|
45
45
|
`oauth_code` or `oauth_client`, plus `ownership` (`org` or per member).
|
|
46
|
+
`oauth_code` may add `authorizationParams`, extra query parameters of the authorize request
|
|
47
|
+
(e.g. `{ "access_type": "offline", "prompt": "consent" }` for Google): at most 10, lowercase
|
|
48
|
+
names, plain values, never a secret, none of `OAUTH_RESERVED_AUTHORIZATION_PARAMS`.
|
|
46
49
|
- `defaultToolPolicies`: tool name to `allow`, `ask` or `deny`. When unsure, do not write `allow`.
|
|
47
50
|
|
|
48
51
|
Credentials and secret config are entered by the person on the `Platform` confirmation card (name
|
package/dist/connector-auth.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Authorization request parameters the kernel sets itself, or that would change what the callback
|
|
4
|
+
* or the token exchange relies on, or that never belong on a URL. `oauth_code`
|
|
5
|
+
* `authorizationParams` cannot use them, nor can the query of a manual `authorizationUrl`; the kernel
|
|
6
|
+
* checks the list again before it builds an authorize URL.
|
|
7
|
+
*/
|
|
8
|
+
export declare const OAUTH_RESERVED_AUTHORIZATION_PARAMS: readonly ["response_type", "client_id", "redirect_uri", "state", "code_challenge", "code_challenge_method", "scope", "resource", "response_mode", "request", "request_uri", "nonce", "dpop_jkt", "authorization_details", "client_secret", "client_assertion", "client_assertion_type", "code", "code_verifier", "grant_type", "refresh_token"];
|
|
2
9
|
/**
|
|
3
10
|
* Authentication method: only the type and non-secret fields; credential values go through the
|
|
4
11
|
* kernel's `credential` / credentials API.
|
|
@@ -54,6 +61,7 @@ export declare const ConnectorAuthSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
54
61
|
client_secret_post: "client_secret_post";
|
|
55
62
|
}>>;
|
|
56
63
|
tokenTypes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
64
|
+
authorizationParams: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
57
65
|
}, z.core.$strict>, z.ZodObject<{
|
|
58
66
|
type: z.ZodLiteral<"oauth_client">;
|
|
59
67
|
ownership: z.ZodLiteral<"org">;
|
package/dist/connector-auth.js
CHANGED
|
@@ -39,6 +39,54 @@ const TokenTypes = z
|
|
|
39
39
|
.regex(/^[A-Za-z][A-Za-z0-9_.-]*$/, "Invalid token type")
|
|
40
40
|
.refine((t) => t.toLowerCase() !== "dpop", "DPoP tokens are not bearer tokens"))
|
|
41
41
|
.max(5);
|
|
42
|
+
/**
|
|
43
|
+
* Authorization request parameters the kernel sets itself, or that would change what the callback
|
|
44
|
+
* or the token exchange relies on, or that never belong on a URL. `oauth_code`
|
|
45
|
+
* `authorizationParams` cannot use them, nor can the query of a manual `authorizationUrl`; the kernel
|
|
46
|
+
* checks the list again before it builds an authorize URL.
|
|
47
|
+
*/
|
|
48
|
+
export const OAUTH_RESERVED_AUTHORIZATION_PARAMS = [
|
|
49
|
+
// set by the kernel's authorize request
|
|
50
|
+
"response_type",
|
|
51
|
+
"client_id",
|
|
52
|
+
"redirect_uri",
|
|
53
|
+
"state",
|
|
54
|
+
"code_challenge",
|
|
55
|
+
"code_challenge_method",
|
|
56
|
+
"scope",
|
|
57
|
+
"resource",
|
|
58
|
+
// would change what the callback or the token exchange relies on
|
|
59
|
+
"response_mode",
|
|
60
|
+
"request",
|
|
61
|
+
"request_uri",
|
|
62
|
+
"nonce",
|
|
63
|
+
"dpop_jkt",
|
|
64
|
+
"authorization_details",
|
|
65
|
+
// credentials and token-endpoint names
|
|
66
|
+
"client_secret",
|
|
67
|
+
"client_assertion",
|
|
68
|
+
"client_assertion_type",
|
|
69
|
+
"code",
|
|
70
|
+
"code_verifier",
|
|
71
|
+
"grant_type",
|
|
72
|
+
"refresh_token",
|
|
73
|
+
];
|
|
74
|
+
const RESERVED_PARAMS = new Set(OAUTH_RESERVED_AUTHORIZATION_PARAMS);
|
|
75
|
+
const reservedParamMessage = (name) => `"${name}" is set by the kernel and cannot be an authorization parameter`;
|
|
76
|
+
const MAX_AUTHORIZATION_PARAMS = 10;
|
|
77
|
+
/**
|
|
78
|
+
* Extra query parameters of the authorize request (e.g. Google's `access_type: "offline"`,
|
|
79
|
+
* `prompt: "consent"`): names `[a-z][a-z0-9_]` up to 40 characters, values 1-200 printable ASCII
|
|
80
|
+
* characters, at most 10, none of {@link OAUTH_RESERVED_AUTHORIZATION_PARAMS}. Not secrets: they
|
|
81
|
+
* are stored in plain JSON and shown in the browser's address bar.
|
|
82
|
+
*/
|
|
83
|
+
const AuthorizationParams = z
|
|
84
|
+
.record(z.string().regex(/^[a-z][a-z0-9_]{0,39}$/, "Invalid authorization parameter name"), z.string().regex(/^[\x20-\x7E]{1,200}$/, "Invalid authorization parameter value"))
|
|
85
|
+
.refine((p) => Object.keys(p).length <= MAX_AUTHORIZATION_PARAMS, {
|
|
86
|
+
message: `At most ${MAX_AUTHORIZATION_PARAMS} authorization parameters`,
|
|
87
|
+
})
|
|
88
|
+
.describe("Extra query parameters of the OAuth authorize request (e.g. access_type, prompt). " +
|
|
89
|
+
"Never put a secret here.");
|
|
42
90
|
/**
|
|
43
91
|
* Authentication method: only the type and non-secret fields; credential values go through the
|
|
44
92
|
* kernel's `credential` / credentials API.
|
|
@@ -77,9 +125,29 @@ export const ConnectorAuthSchema = z.discriminatedUnion("type", [
|
|
|
77
125
|
client: z.enum(["dcr", "manual"]),
|
|
78
126
|
tokenAuthMethod: TokenAuthMethod.optional(),
|
|
79
127
|
tokenTypes: TokenTypes.optional(),
|
|
128
|
+
authorizationParams: AuthorizationParams.optional(),
|
|
80
129
|
})
|
|
81
130
|
.strict()
|
|
82
131
|
.superRefine((a, ctx) => {
|
|
132
|
+
for (const name of Object.keys(a.authorizationParams ?? {})) {
|
|
133
|
+
if (RESERVED_PARAMS.has(name))
|
|
134
|
+
ctx.addIssue({
|
|
135
|
+
code: "custom",
|
|
136
|
+
path: ["authorizationParams", name],
|
|
137
|
+
message: reservedParamMessage(name),
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
// A query in a manual endpoint stays (RFC 6749 §3.1), but never with a name the kernel owns
|
|
141
|
+
if (a.authorizationUrl !== undefined && URL.canParse(a.authorizationUrl)) {
|
|
142
|
+
for (const name of new Set(new URL(a.authorizationUrl).searchParams.keys())) {
|
|
143
|
+
if (RESERVED_PARAMS.has(name.toLowerCase()))
|
|
144
|
+
ctx.addIssue({
|
|
145
|
+
code: "custom",
|
|
146
|
+
path: ["authorizationUrl"],
|
|
147
|
+
message: reservedParamMessage(name),
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
83
151
|
if (a.discovery === "manual") {
|
|
84
152
|
for (const k of ["authorizationUrl", "tokenUrl"]) {
|
|
85
153
|
if (a[k] === undefined)
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED