@cloudflare/workers-auth 0.5.0 → 0.5.2

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.
@@ -1,6 +1,6 @@
1
- import { a as ConfigStorage, A as AuthConfigStorage, U as UserAuthConfig, b as OAuthFlowContext, k as ProfileStore } from '../file-format-CWtMNfzC.mjs';
2
- import { C as CliDescriptor, U as UserPreferences, A as AuthContext, a as CloudflareAuth, K as KeyringPreferenceContext, S as SetKeyringPreferenceResult } from '../keyring-preference-DMsAtawt.mjs';
3
- export { b as CloudflareLoginProps } from '../keyring-preference-DMsAtawt.mjs';
1
+ import { a as ConfigStorage, A as AuthConfigStorage, U as UserAuthConfig, b as OAuthFlowContext, k as ProfileStore } from '../file-format-B1KgHuUR.mjs';
2
+ import { C as CliDescriptor, U as UserPreferences, A as AuthContext, a as CloudflareAuth, K as KeyringPreferenceContext, S as SetKeyringPreferenceResult } from '../keyring-preference-BgjU5DM9.mjs';
3
+ export { b as CloudflareLoginProps } from '../keyring-preference-BgjU5DM9.mjs';
4
4
  import '@cloudflare/workers-utils';
5
5
 
6
6
  /**
package/dist/cf/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { createAuthConfigFileHelpers, createPreferences, createKeyringPreference, createFileStorage, createCloudflareAuth, createCloudflareProfileStore } from '../chunk-WJE5I5WS.mjs';
2
- import '../chunk-FX4KV7FS.mjs';
1
+ import { createAuthConfigFileHelpers, createPreferences, createKeyringPreference, createFileStorage, createCloudflareAuth, createCloudflareProfileStore } from '../chunk-7PS36DJW.mjs';
2
+ import '../chunk-5WRJ2ZUV.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';
@@ -160,7 +160,8 @@ var CF_CLI = {
160
160
  cliName: CF_CLI_NAME,
161
161
  commands: {
162
162
  login: "cf auth login",
163
- whoami: "cf auth whoami"
163
+ whoami: "cf auth whoami",
164
+ createProfile: "cf auth create"
164
165
  },
165
166
  keyringServiceName: CF_KEYRING_SERVICE_NAME,
166
167
  clientId: getClientIdFromEnv,
@@ -1,5 +1,5 @@
1
1
  import { __name } from './chunk-O6YSETKJ.mjs';
2
- import { getEnvironmentVariableFactory, getCloudflareApiEnvironmentFromEnv, getBooleanEnvironmentVariableFactory, UserError, readFileSync, getCloudflareApiBaseUrl, COMPLIANCE_REGION_CONFIG_PUBLIC, FatalError, getCloudflareComplianceRegion, parseTOML } from '@cloudflare/workers-utils';
2
+ import { getEnvironmentVariableFactory, getCloudflareApiEnvironmentFromEnv, getBooleanEnvironmentVariableFactory, UserError, readFileSync, isNonInteractiveOrCI, getCloudflareApiBaseUrl, COMPLIANCE_REGION_CONFIG_PUBLIC, FatalError, getCloudflareComplianceRegion, parseTOML } from '@cloudflare/workers-utils';
3
3
  import { spawnSync } from 'node:child_process';
4
4
  import { fetch } from 'undici';
5
5
  import { webcrypto, createHash, randomBytes, createCipheriv, createDecipheriv } from 'node:crypto';
@@ -173,7 +173,6 @@ async function domainUsesAccess(domain, logger) {
173
173
  __name(domainUsesAccess, "domainUsesAccess");
174
174
  async function getAccessHeaders(domain, options) {
175
175
  const logger = options.logger;
176
- const isNonInteractiveOrCI = options.isNonInteractiveOrCI;
177
176
  const clientId = getAccessClientIdFromEnv();
178
177
  const clientSecret = getAccessClientSecretFromEnv();
179
178
  if (clientId && clientSecret) {
@@ -198,7 +197,7 @@ async function getAccessHeaders(domain, options) {
198
197
  logger.debug("Using cached Access headers for domain:", domain);
199
198
  return headersCache[domain];
200
199
  }
201
- if (isNonInteractiveOrCI()) {
200
+ if ((options.isNonInteractiveOrCI ?? isNonInteractiveOrCI)()) {
202
201
  throw new UserError(
203
202
  `The domain "${domain}" is behind Cloudflare Access, but no Access Service Token credentials were found and the current environment is non-interactive.
204
203
  Set the CLOUDFLARE_ACCESS_CLIENT_ID and CLOUDFLARE_ACCESS_CLIENT_SECRET environment variables to authenticate with an Access Service Token.
@@ -798,7 +797,7 @@ async function getAuthURL(scopes, clientId, redirectUri, state, generators) {
798
797
  });
799
798
  }
800
799
  __name(getAuthURL, "getAuthURL");
801
- async function exchangeRefreshTokenForAccessToken(logger, isNonInteractiveOrCI, clientId, storage) {
800
+ async function exchangeRefreshTokenForAccessToken(logger, isNonInteractiveOrCI2, clientId, storage) {
802
801
  const storedRefreshToken = readStoredAuthState({
803
802
  warningLogger: logger,
804
803
  storage
@@ -811,7 +810,7 @@ async function exchangeRefreshTokenForAccessToken(logger, isNonInteractiveOrCI,
811
810
  refresh_token: storedRefreshToken?.value ?? "",
812
811
  client_id: clientId
813
812
  });
814
- const response = await fetchAuthToken(params, logger, isNonInteractiveOrCI);
813
+ const response = await fetchAuthToken(params, logger, isNonInteractiveOrCI2);
815
814
  if (response.status >= 400) {
816
815
  let tokenExchangeResErr = void 0;
817
816
  try {
@@ -858,7 +857,7 @@ async function exchangeRefreshTokenForAccessToken(logger, isNonInteractiveOrCI,
858
857
  }
859
858
  }
860
859
  __name(exchangeRefreshTokenForAccessToken, "exchangeRefreshTokenForAccessToken");
861
- async function exchangeAuthCodeForAccessToken(state, logger, isNonInteractiveOrCI, clientId, redirectUri) {
860
+ async function exchangeAuthCodeForAccessToken(state, logger, isNonInteractiveOrCI2, clientId, redirectUri) {
862
861
  const { authorizationCode, codeVerifier = "" } = state;
863
862
  if (!codeVerifier) {
864
863
  logger.warn("No code verifier is being sent.");
@@ -872,7 +871,7 @@ async function exchangeAuthCodeForAccessToken(state, logger, isNonInteractiveOrC
872
871
  client_id: clientId,
873
872
  code_verifier: codeVerifier
874
873
  });
875
- const response = await fetchAuthToken(params, logger, isNonInteractiveOrCI);
874
+ const response = await fetchAuthToken(params, logger, isNonInteractiveOrCI2);
876
875
  if (!response.ok) {
877
876
  const { error } = await getJSONFromResponse(response, logger);
878
877
  if (error === "invalid_grant") {
@@ -900,7 +899,7 @@ async function exchangeAuthCodeForAccessToken(state, logger, isNonInteractiveOrC
900
899
  return accessContext;
901
900
  }
902
901
  __name(exchangeAuthCodeForAccessToken, "exchangeAuthCodeForAccessToken");
903
- async function fetchAuthToken(body, logger, isNonInteractiveOrCI) {
902
+ async function fetchAuthToken(body, logger, isNonInteractiveOrCI2) {
904
903
  const headers = {
905
904
  "Content-Type": "application/x-www-form-urlencoded"
906
905
  };
@@ -914,7 +913,7 @@ async function fetchAuthToken(body, logger, isNonInteractiveOrCI) {
914
913
  );
915
914
  const accessHeaders = await getCloudflareAccessHeaders({
916
915
  logger,
917
- isNonInteractiveOrCI
916
+ isNonInteractiveOrCI: isNonInteractiveOrCI2
918
917
  });
919
918
  Object.assign(headers, accessHeaders);
920
919
  }
@@ -1471,7 +1470,7 @@ function createProfileStore(args) {
1471
1470
  throw new UserError(
1472
1471
  `No profile is directly bound to "${formatDirectoryForUserError(normalizedDir)}". The active profile "${parentBinding.profile}" is bound at "${formatDirectoryForUserError(
1473
1472
  parentBinding.dir
1474
- )}". Run \`wrangler auth deactivate\` from that directory instead.`,
1473
+ )}". Run the deactivate command from that directory instead.`,
1475
1474
  { telemetryMessage: "auth deactivate wrong directory" }
1476
1475
  );
1477
1476
  }
@@ -1550,7 +1549,7 @@ __name(createProfileStore, "createProfileStore");
1550
1549
  function validateProfileName(name) {
1551
1550
  if (RESERVED_PROFILE_NAMES.includes(name.toLowerCase())) {
1552
1551
  throw new UserError(
1553
- `"${name}" is a reserved profile name. Use \`wrangler login\` and \`wrangler logout\` to manage the default profile, which applies as a global fallback.`,
1552
+ `"${name}" is a reserved profile name. Use the login and logout commands to manage the default profile, which applies as a global fallback.`,
1554
1553
  { telemetryMessage: "auth profile reserved name" }
1555
1554
  );
1556
1555
  }
@@ -2888,7 +2887,6 @@ function setKeyringEntryFactory(factory) {
2888
2887
  entryFactoryOverride = factory;
2889
2888
  }
2890
2889
  __name(setKeyringEntryFactory, "setKeyringEntryFactory");
2891
- var dynamicRequire = createRequire(__filename);
2892
2890
  function resolveKeyringEntryFactory(installDir) {
2893
2891
  if (entryFactoryOverride !== void 0) {
2894
2892
  return entryFactoryOverride;
@@ -2899,7 +2897,7 @@ function resolveKeyringEntryFactory(installDir) {
2899
2897
  "`@napi-rs/keyring` binding not found. Call `installKeyringBindingSync()` first."
2900
2898
  );
2901
2899
  }
2902
- const mod = dynamicRequire(bindingPath);
2900
+ const mod = createRequire(bindingPath)(bindingPath);
2903
2901
  return (service, account) => new mod.Entry(service, account);
2904
2902
  }
2905
2903
  __name(resolveKeyringEntryFactory, "resolveKeyringEntryFactory");
@@ -1,4 +1,4 @@
1
- import { stringifyFile, parseFile, dedent, createCredentialStorageContext, createOAuthFlow, getAuthFromEnv, createProfileStore, getCloudflareAccountIdFromEnv, getAuthConfigFilePath, getEncryptedAuthConfigFilePath, scrubEncryptedCredentials, validateProfileName, getCloudflareAuthUseKeyringFromEnv } from './chunk-FX4KV7FS.mjs';
1
+ import { stringifyFile, parseFile, dedent, createCredentialStorageContext, createOAuthFlow, getAuthFromEnv, createProfileStore, getCloudflareAccountIdFromEnv, getAuthConfigFilePath, getEncryptedAuthConfigFilePath, scrubEncryptedCredentials, validateProfileName, getCloudflareAuthUseKeyringFromEnv } from './chunk-5WRJ2ZUV.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';
@@ -1,4 +1,4 @@
1
- import { ComplianceConfig, ApiCredentials } from '@cloudflare/workers-utils';
1
+ import { Logger, ComplianceConfig, ApiCredentials } from '@cloudflare/workers-utils';
2
2
 
3
3
  /**
4
4
  * Pluggable persistence for a typed config blob.
@@ -126,13 +126,7 @@ interface OAuthConsentPages {
126
126
  * Subset of the wrangler `logger` singleton used by the OAuth flow.
127
127
  * Consumers pass in an implementation that maps to their own logging surface.
128
128
  */
129
- interface OAuthFlowLogger {
130
- debug(...args: unknown[]): void;
131
- info(...args: unknown[]): void;
132
- log(...args: unknown[]): void;
133
- warn(...args: unknown[]): void;
134
- error(...args: unknown[]): void;
135
- }
129
+ type OAuthFlowLogger = Logger;
136
130
  /**
137
131
  * Dependency-injection surface for {@link createOAuthFlow}.
138
132
  *
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { O as OAuthFlowLogger, U as UserAuthConfig, A as AuthConfigStorage, C as CredentialStore, F as FileFormat } from './file-format-CWtMNfzC.mjs';
2
- export { a as ConfigStorage, D as DeactivateDirectoryResult, i as DirectoryBindingOperations, j as DirectoryBindingsStorage, L as LoginOrRefreshFailureReason, d as LoginOrRefreshResult, e as LoginProps, b as OAuthFlowContext, P as ProfileConfigOperations, k as ProfileStore, T as TemporaryPreviewAccount, c as createOAuthFlow, h as createProfileStore, g as generateAuthUrl, f as generateRandomState, v as validateProfileName } from './file-format-CWtMNfzC.mjs';
1
+ import { O as OAuthFlowLogger, U as UserAuthConfig, A as AuthConfigStorage, C as CredentialStore, F as FileFormat } from './file-format-B1KgHuUR.mjs';
2
+ export { a as ConfigStorage, D as DeactivateDirectoryResult, i as DirectoryBindingOperations, j as DirectoryBindingsStorage, L as LoginOrRefreshFailureReason, d as LoginOrRefreshResult, e as LoginProps, b as OAuthFlowContext, P as ProfileConfigOperations, k as ProfileStore, T as TemporaryPreviewAccount, c as createOAuthFlow, h as createProfileStore, g as generateAuthUrl, f as generateRandomState, v as validateProfileName } from './file-format-B1KgHuUR.mjs';
3
3
  import { ApiCredentials } from '@cloudflare/workers-utils';
4
4
  import { SpawnSyncReturns } from 'node:child_process';
5
5
 
@@ -61,7 +61,7 @@ declare function domainUsesAccess(domain: string, logger: OAuthFlowLogger): Prom
61
61
  */
62
62
  declare function getAccessHeaders(domain: string, options: {
63
63
  logger: OAuthFlowLogger;
64
- isNonInteractiveOrCI: () => boolean;
64
+ isNonInteractiveOrCI?: () => boolean;
65
65
  }): Promise<Record<string, string>>;
66
66
 
67
67
  /**
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-FX4KV7FS.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-5WRJ2ZUV.mjs';
2
2
  import './chunk-O6YSETKJ.mjs';
@@ -1,4 +1,4 @@
1
- import { l as OAuthConsentPages, F as FileFormat, b as OAuthFlowContext, C as CredentialStore, d as LoginOrRefreshResult, U as UserAuthConfig } from './file-format-CWtMNfzC.mjs';
1
+ import { l as OAuthConsentPages, F as FileFormat, b as OAuthFlowContext, C as CredentialStore, d as LoginOrRefreshResult, U as UserAuthConfig } from './file-format-B1KgHuUR.mjs';
2
2
  import { ApiCredentials, ComplianceConfig } from '@cloudflare/workers-utils';
3
3
 
4
4
  /** Minimal shape of the interactive `select` prompt's options for account selection. */
@@ -48,7 +48,7 @@ interface CliDescriptor {
48
48
  commands: {
49
49
  login: string;
50
50
  whoami: string;
51
- createProfile?: string;
51
+ createProfile: string;
52
52
  };
53
53
  /**
54
54
  * OS-keyring service identifier. Becomes the `-s` arg to macOS `security`,