@cloudflare/workers-auth 0.5.3 → 0.5.5

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/cf/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { createAuthConfigFileHelpers, createPreferences, createKeyringPreference, createFileStorage, createCloudflareAuth, createCloudflareProfileStore } from '../chunk-7PS36DJW.mjs';
2
- import '../chunk-5WRJ2ZUV.mjs';
1
+ import { createAuthConfigFileHelpers, createPreferences, createKeyringPreference, createFileStorage, createCloudflareAuth, createCloudflareProfileStore } from '../chunk-RTFTHYPD.mjs';
2
+ import '../chunk-PBW6773T.mjs';
3
3
  import { __name } from '../chunk-O6YSETKJ.mjs';
4
4
  import { getEnvironmentVariableFactory, getGlobalConfigPath, getCloudflareApiEnvironmentFromEnv } from '@cloudflare/workers-utils';
5
5
  import path from 'node:path';
@@ -1,6 +1,6 @@
1
1
  import { __name } from './chunk-O6YSETKJ.mjs';
2
2
  import { getEnvironmentVariableFactory, getCloudflareApiEnvironmentFromEnv, getBooleanEnvironmentVariableFactory, UserError, readFileSync, isNonInteractiveOrCI, getCloudflareApiBaseUrl, COMPLIANCE_REGION_CONFIG_PUBLIC, FatalError, getCloudflareComplianceRegion, parseTOML } from '@cloudflare/workers-utils';
3
- import { spawnSync } from 'node:child_process';
3
+ import { spawn, spawnSync } from 'node:child_process';
4
4
  import { fetch } from 'undici';
5
5
  import { webcrypto, createHash, randomBytes, createCipheriv, createDecipheriv } from 'node:crypto';
6
6
  import { TextEncoder } from 'node:util';
@@ -208,14 +208,14 @@ See https://developers.cloudflare.com/cloudflare-one/access-controls/service-cre
208
208
  );
209
209
  }
210
210
  logger.debug("Spawning cloudflared to get Access token for domain:");
211
- const output = spawnSync("cloudflared", ["access", "login", domain]);
211
+ const output = await spawnCloudflaredAccessLogin(domain, options.signal);
212
212
  if (output.error) {
213
213
  throw new UserError(
214
214
  "To use Wrangler with Cloudflare Access, please install `cloudflared` from https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/installation",
215
215
  { telemetryMessage: "user access missing cloudflared" }
216
216
  );
217
217
  }
218
- const stringOutput = output.stdout.toString();
218
+ const stringOutput = output.stdout;
219
219
  logger.debug("cloudflared output:", stringOutput);
220
220
  const matches = stringOutput.match(/fetched your token:\n\n(.*)/m);
221
221
  if (matches && matches.length >= 2) {
@@ -227,6 +227,33 @@ See https://developers.cloudflare.com/cloudflare-one/access-controls/service-cre
227
227
  throw new Error("Failed to authenticate with Cloudflare Access");
228
228
  }
229
229
  __name(getAccessHeaders, "getAccessHeaders");
230
+ function spawnCloudflaredAccessLogin(domain, signal) {
231
+ return new Promise((resolve, reject) => {
232
+ const child = spawn("cloudflared", ["access", "login", domain], { signal });
233
+ const stdoutChunks = [];
234
+ child.stdout.on("data", (chunk) => stdoutChunks.push(chunk));
235
+ child.stderr.resume();
236
+ const killChild = /* @__PURE__ */ __name(() => child.kill(), "killChild");
237
+ process.once("exit", killChild);
238
+ child.on("error", (error) => {
239
+ process.removeListener("exit", killChild);
240
+ if (signal?.aborted) {
241
+ reject(error);
242
+ return;
243
+ }
244
+ resolve({ error, stdout: "" });
245
+ });
246
+ child.on("close", () => {
247
+ process.removeListener("exit", killChild);
248
+ if (signal?.aborted) {
249
+ reject(signal.reason ?? new Error("The operation was aborted"));
250
+ return;
251
+ }
252
+ resolve({ stdout: Buffer.concat(stdoutChunks).toString() });
253
+ });
254
+ });
255
+ }
256
+ __name(spawnCloudflaredAccessLogin, "spawnCloudflaredAccessLogin");
230
257
  async function getCloudflareAccessHeaders(options) {
231
258
  const cfAuthToken = getCfAuthorizationTokenFromEnv();
232
259
  if (cfAuthToken !== void 0) {
@@ -1,4 +1,4 @@
1
- import { stringifyFile, parseFile, dedent, createCredentialStorageContext, createOAuthFlow, getAuthFromEnv, createProfileStore, getCloudflareAccountIdFromEnv, getAuthConfigFilePath, getEncryptedAuthConfigFilePath, scrubEncryptedCredentials, validateProfileName, getCloudflareAuthUseKeyringFromEnv } from './chunk-5WRJ2ZUV.mjs';
1
+ import { stringifyFile, parseFile, dedent, createCredentialStorageContext, createOAuthFlow, getAuthFromEnv, createProfileStore, getCloudflareAccountIdFromEnv, getAuthConfigFilePath, getEncryptedAuthConfigFilePath, scrubEncryptedCredentials, validateProfileName, getCloudflareAuthUseKeyringFromEnv } from './chunk-PBW6773T.mjs';
2
2
  import { __name } from './chunk-O6YSETKJ.mjs';
3
3
  import { existsSync, rmSync, mkdirSync, writeFileSync, chmodSync, readFileSync as readFileSync$1, readdirSync } from 'node:fs';
4
4
  import path3 from 'node:path';
package/dist/index.d.mts CHANGED
@@ -62,6 +62,8 @@ declare function domainUsesAccess(domain: string, logger: OAuthFlowLogger): Prom
62
62
  declare function getAccessHeaders(domain: string, options: {
63
63
  logger: OAuthFlowLogger;
64
64
  isNonInteractiveOrCI?: () => boolean;
65
+ /** Aborts a pending `cloudflared` authorization and kills its process. */
66
+ signal?: AbortSignal;
65
67
  }): Promise<Record<string, string>>;
66
68
 
67
69
  /**
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export { EncryptedFileCredentialStore, FileCredentialStore, LinuxSecretToolKeyProvider, MacSecurityKeyProvider, NapiKeyringKeyProvider, PINNED_KEYRING_VERSION, PKCE_CHARSET, TEMPORARY_TERMS_NOTICE, TEMPORARY_TERMS_PROMPT, clearAccessCaches, clearCredentialStorageState, createCredentialStorageContext, createOAuthFlow, createProfileStore, decryptString, domainUsesAccess, encryptString, findKeyringBinding, generateAuthUrl, generateKey, generateRandomState, getAccessHeaders, getAuthConfigFilePath, getAuthFromEnv, getAuthUrlFromEnv, getCloudflareAPITokenFromEnv, getCloudflareAccountIdFromEnv, getCloudflareAuthUseKeyringFromEnv, getCloudflareGlobalAuthEmailFromEnv, getCloudflareGlobalAuthKeyFromEnv, getEncryptedAuthConfigFilePath, getKeyringAccountName, getKeyringInstallDir, installKeyringBindingSync, parseEncryptedEnvelope, probeSecretTool, readStoredAuthState, resetCredentialStorageState, resolveKeyProvider, scrubEncryptedCredentials, setKeyProviderFactoryForTesting, setKeyringEntryFactory, setLinuxSecretToolRunner, setMacSecurityCommandRunner, setNpmRunner, validateProfileName } from './chunk-5WRJ2ZUV.mjs';
1
+ export { EncryptedFileCredentialStore, FileCredentialStore, LinuxSecretToolKeyProvider, MacSecurityKeyProvider, NapiKeyringKeyProvider, PINNED_KEYRING_VERSION, PKCE_CHARSET, TEMPORARY_TERMS_NOTICE, TEMPORARY_TERMS_PROMPT, clearAccessCaches, clearCredentialStorageState, createCredentialStorageContext, createOAuthFlow, createProfileStore, decryptString, domainUsesAccess, encryptString, findKeyringBinding, generateAuthUrl, generateKey, generateRandomState, getAccessHeaders, getAuthConfigFilePath, getAuthFromEnv, getAuthUrlFromEnv, getCloudflareAPITokenFromEnv, getCloudflareAccountIdFromEnv, getCloudflareAuthUseKeyringFromEnv, getCloudflareGlobalAuthEmailFromEnv, getCloudflareGlobalAuthKeyFromEnv, getEncryptedAuthConfigFilePath, getKeyringAccountName, getKeyringInstallDir, installKeyringBindingSync, parseEncryptedEnvelope, probeSecretTool, readStoredAuthState, resetCredentialStorageState, resolveKeyProvider, scrubEncryptedCredentials, setKeyProviderFactoryForTesting, setKeyringEntryFactory, setLinuxSecretToolRunner, setMacSecurityCommandRunner, setNpmRunner, validateProfileName } from './chunk-PBW6773T.mjs';
2
2
  import './chunk-O6YSETKJ.mjs';