jive-connector-domain-host-cloudflare 0.5.0 → 0.5.1

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 CHANGED
@@ -54,7 +54,7 @@ A connection asks for `zone.read zone.write dns.read dns.write`, plus `offline_a
54
54
 
55
55
  1. The server calls `deviceSignIn.start({ owner, organization })`. The component asks Cloudflare for a code at `/oauth2/device/auth`, seals the device code in its own `deviceSignIns` table, and answers `{ status: "started", requestId, userCode, verificationUrl, verificationUrlComplete, expiresAt, pollAfterMs }`. `verificationUrlComplete` is Cloudflare's page with the code already in it, so approving is one click on any device. A page that isn't on `https://dash.cloudflare.com`, Cloudflare's sign-in server, is refused before anything is stored. `deviceSignIn.present({ owner, organization, requestId })` answers the same instructions again while the sign-in waits.
56
56
  2. The person approves on Cloudflare's page.
57
- 3. The server calls `deviceSignIn.poll({ owner, requestId, organization, uses })` every `pollAfterMs`, `organization` being the one that started it. It answers `pending` until the person approves, then `connected` with the account and its `connectionId`, `denied` or `expired`. On approval the component exchanges the sealed device code itself, so the token first exists sealed inside the component and no answer holds it.
57
+ 3. The server calls `deviceSignIn.poll({ owner, requestId, organization, uses: [{ organization, reach: ["*"] }] })` every `pollAfterMs`, `organization` being the one that started it. It answers `pending` until the person approves, then `connected` with the account and its `connectionId`, `denied` or `expired`. The connection is that one organization's, reaching all of the account, made through `connection.connect`. Any other `uses` (a second organization, a named reach) is refused before Cloudflare is asked for a token. On approval the component exchanges the sealed device code itself, so the token first exists sealed inside the component and no answer holds it.
58
58
 
59
59
  **Refreshing.** Cloudflare's access token expires. The component renews it with the refresh token during its last minute, before the token is used for a call, and stores the renewed one first. A refresh token Cloudflare doesn't replace is kept. A refresh Cloudflare refuses ends that call before Cloudflare's API is asked anything, and the organization connects again.
60
60
 
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * The `cf` CLI's device sign-in, which Jive's server runs through this component with jive-abstract-connector's shared
3
3
  * device sign-in. `begin` asks Cloudflare for a code; `approve` exchanges the sealed device code through the guarded
4
- * `connection.connectShared`, so the token first exists inside the component.
4
+ * `connection.connect` for the one organization that started the sign-in, so the token first exists inside the component.
5
5
  */
6
6
  export declare const start: import("convex/server").RegisteredAction<"public", {
7
7
  inputs?: Record<string, string> | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"deviceSignIn.d.ts","sourceRoot":"","sources":["../../../../src/component/deviceSignIn.ts"],"names":[],"mappings":"AAeA;;;;GAIG;AACH,eAAO,MAAQ,KAAK;;;;;;;;;;;;;;;KAAE,IAAI;;;;;;;;;;;;;;;;;;;;;;;;KAAE,OAAO;;;;;;;;;;;;YAAE,OAAO;;;;;;;;;;;;;;;;;KAAE,WAAW;;;mBAAE,QAAQ;;;;;;;;;;;;;;;;;;;;;KAAE,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAAE,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BpF,CAAC"}
1
+ {"version":3,"file":"deviceSignIn.d.ts","sourceRoot":"","sources":["../../../../src/component/deviceSignIn.ts"],"names":[],"mappings":"AAkBA;;;;GAIG;AACH,eAAO,MAAQ,KAAK;;;;;;;;;;;;;;;KAAE,IAAI;;;;;;;;;;;;;;;;;;;;;;;;KAAE,OAAO;;;;;;;;;;;;YAAE,OAAO;;;;;;;;;;;;;;;;;KAAE,WAAW;;;mBAAE,QAAQ;;;;;;;;;;;;;;;;;;;;;KAAE,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAAE,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCpF,CAAC"}
@@ -8,12 +8,15 @@ import { CLOUDFLARE } from "./cloudflare/http/impl";
8
8
  import { cloudflare } from "./connector";
9
9
  /** RFC 8628 §3.5: a `slow_down` answer adds five seconds to the interval. */
10
10
  const SLOW_DOWN_MS = 5_000;
11
- /** The refusals a not-yet-approved device code answers, as `connection.connectShared` words them. */
11
+ /** The reach the server grants a device sign-in: the whole account, for the one organization that started it. */
12
+ const REACH_EVERYTHING = "*";
13
+ const ONLY_THE_STARTING_ORGANIZATION = "A Cloudflare sign-in serves only the organization that started it, with all of the account";
14
+ /** The refusals a not-yet-approved device code answers, as `connection.connect` words them. */
12
15
  const connectingFailed = (reason) => `connecting failed: ${reason}`;
13
16
  /**
14
17
  * The `cf` CLI's device sign-in, which Jive's server runs through this component with jive-abstract-connector's shared
15
18
  * device sign-in. `begin` asks Cloudflare for a code; `approve` exchanges the sealed device code through the guarded
16
- * `connection.connectShared`, so the token first exists inside the component.
19
+ * `connection.connect` for the one organization that started the sign-in, so the token first exists inside the component.
17
20
  */
18
21
  export const { start, poll, present, reserve, cancelStart, activate, claim, finishPoll } = defineDeviceSignIn({
19
22
  system: cloudflareIdentity.system,
@@ -28,8 +31,14 @@ export const { start, poll, present, reserve, cancelStart, activate, claim, fini
28
31
  const { verificationUrlComplete, ...grant } = started.success;
29
32
  return verificationUrlComplete === null ? grant : { ...grant, verificationUrlComplete };
30
33
  },
31
- approve: async (ctx, { owner, uses, deviceCode }) => {
32
- const answer = await ctx.runAction(api.connection.connectShared, { owner, uses, blob: JSON.stringify({ deviceCode }) });
34
+ approve: async (ctx, { organization, uses, deviceCode }) => {
35
+ // The server authorizes only the organization that started the sign-in, which the factory bound to it, to all of
36
+ // the account. Anything else it is asked to serve is refused before Cloudflare is asked for a token.
37
+ const only = uses[0];
38
+ if (uses.length !== 1 || only === undefined || only.organization !== organization || only.reach.length !== 1 || only.reach[0] !== REACH_EVERYTHING) {
39
+ return { status: "refused", reason: ONLY_THE_STARTING_ORGANIZATION };
40
+ }
41
+ const answer = await ctx.runAction(api.connection.connect, { organization, reach: [REACH_EVERYTHING], blob: JSON.stringify({ deviceCode }) });
33
42
  if (answer.status === "connected") {
34
43
  return {
35
44
  status: "connected", account: answer.account.name, connectionId: answer.connection,
@@ -1 +1 @@
1
- {"version":3,"file":"deviceSignIn.js","sourceRoot":"","sources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"jive-connector-domain-host-cloudflare",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "license": "MIT",
5
5
  "description": "A Jive connector to Cloudflare: a Convex component that provisions and reads zones and DNS records as one connected Cloudflare account, implementing jive-abstract-connector-domain-host's contract.",
6
6
  "type": "module",
@@ -9,14 +9,17 @@ import { cloudflare } from "./connector";
9
9
 
10
10
  /** RFC 8628 §3.5: a `slow_down` answer adds five seconds to the interval. */
11
11
  const SLOW_DOWN_MS = 5_000;
12
+ /** The reach the server grants a device sign-in: the whole account, for the one organization that started it. */
13
+ const REACH_EVERYTHING = "*";
14
+ const ONLY_THE_STARTING_ORGANIZATION = "A Cloudflare sign-in serves only the organization that started it, with all of the account";
12
15
 
13
- /** The refusals a not-yet-approved device code answers, as `connection.connectShared` words them. */
16
+ /** The refusals a not-yet-approved device code answers, as `connection.connect` words them. */
14
17
  const connectingFailed = (reason: string): string => `connecting failed: ${reason}`;
15
18
 
16
19
  /**
17
20
  * The `cf` CLI's device sign-in, which Jive's server runs through this component with jive-abstract-connector's shared
18
21
  * device sign-in. `begin` asks Cloudflare for a code; `approve` exchanges the sealed device code through the guarded
19
- * `connection.connectShared`, so the token first exists inside the component.
22
+ * `connection.connect` for the one organization that started the sign-in, so the token first exists inside the component.
20
23
  */
21
24
  export const { start, poll, present, reserve, cancelStart, activate, claim, finishPoll } = defineDeviceSignIn({
22
25
  system: cloudflareIdentity.system,
@@ -30,8 +33,14 @@ export const { start, poll, present, reserve, cancelStart, activate, claim, fini
30
33
  const { verificationUrlComplete, ...grant } = started.success;
31
34
  return verificationUrlComplete === null ? grant : { ...grant, verificationUrlComplete };
32
35
  },
33
- approve: async (ctx, { owner, uses, deviceCode }): Promise<DeviceSignInAttempt> => {
34
- const answer = await ctx.runAction(api.connection.connectShared, { owner, uses, blob: JSON.stringify({ deviceCode }) });
36
+ approve: async (ctx, { organization, uses, deviceCode }): Promise<DeviceSignInAttempt> => {
37
+ // The server authorizes only the organization that started the sign-in, which the factory bound to it, to all of
38
+ // the account. Anything else it is asked to serve is refused before Cloudflare is asked for a token.
39
+ const only = uses[0];
40
+ if (uses.length !== 1 || only === undefined || only.organization !== organization || only.reach.length !== 1 || only.reach[0] !== REACH_EVERYTHING) {
41
+ return { status: "refused", reason: ONLY_THE_STARTING_ORGANIZATION };
42
+ }
43
+ const answer = await ctx.runAction(api.connection.connect, { organization, reach: [REACH_EVERYTHING], blob: JSON.stringify({ deviceCode }) });
35
44
  if (answer.status === "connected") {
36
45
  return {
37
46
  status: "connected", account: answer.account.name, connectionId: answer.connection,