@cloudflare/workers-auth 0.4.2 → 0.5.0
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.d.mts +85 -0
- package/dist/cf/index.mjs +212 -0
- package/dist/chunk-FX4KV7FS.mjs +3702 -0
- package/dist/chunk-WJE5I5WS.mjs +1356 -0
- package/dist/file-format-CWtMNfzC.d.mts +478 -0
- package/dist/index.d.mts +36 -475
- package/dist/index.mjs +2 -3666
- package/dist/keyring-preference-DMsAtawt.d.mts +189 -0
- package/dist/metafile-esm.json +1 -1
- package/dist/wrangler/index.d.mts +119 -0
- package/dist/wrangler/index.mjs +139 -0
- package/package.json +11 -2
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { a as ConfigStorage, A as AuthConfigStorage, U as UserAuthConfig, b as OAuthFlowContext, k as ProfileStore } from '../file-format-CWtMNfzC.mjs';
|
|
2
|
+
import { A as AuthContext, a as CloudflareAuth, b as CloudflareLoginProps, C as CliDescriptor, U as UserPreferences, K as KeyringPreferenceContext, S as SetKeyringPreferenceResult } from '../keyring-preference-DMsAtawt.mjs';
|
|
3
|
+
import '@cloudflare/workers-utils';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A TOML-file-on-disk storage backend, parameterised by the path it reads and
|
|
7
|
+
* writes. Wrangler's historical file format is TOML, so this is a thin
|
|
8
|
+
* `TOML`-bound wrapper over the CLI-agnostic {@link createFileStorage}.
|
|
9
|
+
*/
|
|
10
|
+
declare function createTomlFileStorage<T extends object>(getPath: () => string): ConfigStorage<T>;
|
|
11
|
+
declare const getAuthConfigFilePath: (profile?: string) => string;
|
|
12
|
+
declare const getEncryptedAuthConfigFilePath: (profile?: string) => string;
|
|
13
|
+
declare const defaultAuthConfigStorage: (profile?: string) => AuthConfigStorage;
|
|
14
|
+
declare const readAuthConfigFile: (profile?: string) => UserAuthConfig | undefined;
|
|
15
|
+
declare const writeAuthConfigFile: (config: UserAuthConfig, profile?: string) => void;
|
|
16
|
+
|
|
17
|
+
declare const DefaultScopes: {
|
|
18
|
+
readonly "account:read": "See your account info such as account details, analytics, and memberships.";
|
|
19
|
+
readonly "user:read": "See your user info such as name, email address, and account memberships.";
|
|
20
|
+
readonly "workers:write": "See and change Cloudflare Workers data such as zones, KV storage, namespaces, scripts, and routes.";
|
|
21
|
+
readonly "workers_kv:write": "See and change Cloudflare Workers KV Storage data such as keys and namespaces.";
|
|
22
|
+
readonly "workers_routes:write": "See and change Cloudflare Workers data such as filters and routes.";
|
|
23
|
+
readonly "workers_scripts:write": "See and change Cloudflare Workers scripts, durable objects, subdomains, triggers, and tail data.";
|
|
24
|
+
readonly "workers_tail:read": "See Cloudflare Workers tail and script data.";
|
|
25
|
+
readonly "d1:write": "See and change D1 Databases.";
|
|
26
|
+
readonly "pages:write": "See and change Cloudflare Pages projects, settings and deployments.";
|
|
27
|
+
readonly "zone:read": "Grants read level access to account zone.";
|
|
28
|
+
readonly "ssl_certs:write": "See and manage mTLS certificates for your account";
|
|
29
|
+
readonly "ai:write": "See and change Workers AI catalog and assets";
|
|
30
|
+
readonly "ai-search:write": "See and change AI Search data";
|
|
31
|
+
readonly "ai-search:run": "Run search queries on your AI Search instances";
|
|
32
|
+
readonly "websearch.run": "Run search queries against Cloudflare Web Search";
|
|
33
|
+
readonly "agent-memory:write": "See and change Agent Memory data such as keys and namespaces.";
|
|
34
|
+
readonly "queues:write": "See and change Cloudflare Queues settings and data";
|
|
35
|
+
readonly "pipelines:write": "See and change Cloudflare Pipelines configurations and data";
|
|
36
|
+
readonly "secrets_store:write": "See and change secrets + stores within the Secrets Store";
|
|
37
|
+
readonly "artifacts:write": "See and change Cloudflare Artifacts data such as registries and artifacts";
|
|
38
|
+
readonly "flagship:write": "See and change Flagship feature flags and apps";
|
|
39
|
+
readonly "containers:write": "Manage Workers Containers";
|
|
40
|
+
readonly "cloudchamber:write": "Manage Cloudchamber";
|
|
41
|
+
readonly "connectivity:admin": "See, change, and bind to Connectivity Directory services, including creating services targeting Cloudflare Tunnel.";
|
|
42
|
+
readonly "email_routing:write": "See and change Email Routing settings, rules, and destination addresses.";
|
|
43
|
+
readonly "email_sending:write": "See and change Email Sending settings and configuration.";
|
|
44
|
+
readonly "browser:write": "See and manage Browser Run sessions";
|
|
45
|
+
readonly "challenge-widgets.write": "See and change Turnstile widgets";
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* The possible keys for a Scope.
|
|
49
|
+
*
|
|
50
|
+
* "offline_access" is automatically included.
|
|
51
|
+
*/
|
|
52
|
+
type Scope = keyof typeof DefaultScopes;
|
|
53
|
+
declare let DefaultScopeKeys: Scope[];
|
|
54
|
+
declare function setLoginScopeKeys(scopes: Scope[]): void;
|
|
55
|
+
declare function validateScopeKeys(scopes: string[]): scopes is typeof DefaultScopeKeys;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* `WRANGLER_CLIENT_ID` is the UUID of Wrangler's registered OAuth app, used to
|
|
59
|
+
* identify Wrangler to the Cloudflare OAuth server.
|
|
60
|
+
*
|
|
61
|
+
* This is wrangler CLI config (the app UUIDs and the `WRANGLER_*` variable
|
|
62
|
+
* name are Wrangler's), so it lives in the `/wrangler` layer rather than the
|
|
63
|
+
* shared core — a future `/cf` entrypoint has its own OAuth app.
|
|
64
|
+
*
|
|
65
|
+
* Normally you should not need to set this explicitly. To switch to the staging
|
|
66
|
+
* environment set `WRANGLER_API_ENVIRONMENT=staging` instead.
|
|
67
|
+
*/
|
|
68
|
+
declare const getClientIdFromEnv: () => string;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Keyring service identifier passed to `createCredentialStorageContext` and to
|
|
72
|
+
* the opt-out scrub in wrangler's `commands.ts`. Exported (re-exported from
|
|
73
|
+
* `./index.ts`) so every site stays in sync — this becomes the `-s` arg to
|
|
74
|
+
* macOS `security`, the `service` attribute for Linux `secret-tool`, and the
|
|
75
|
+
* `service` arg to `@napi-rs/keyring`'s `Entry` on Windows.
|
|
76
|
+
*/
|
|
77
|
+
declare const WRANGLER_KEYRING_SERVICE_NAME = "wrangler";
|
|
78
|
+
/** The `redirect_uri` registered on Wrangler's OAuth app. */
|
|
79
|
+
declare const OAUTH_CALLBACK_URL = "http://localhost:8976/oauth/callback";
|
|
80
|
+
|
|
81
|
+
/** @deprecated Use {@link AuthContext}. Kept as an alias for wrangler's historical name. */
|
|
82
|
+
type WranglerAuthContext = AuthContext;
|
|
83
|
+
/** @deprecated Use {@link CloudflareAuth}. */
|
|
84
|
+
type WranglerAuth = CloudflareAuth;
|
|
85
|
+
/** @deprecated Use {@link CloudflareLoginProps}. */
|
|
86
|
+
type WranglerLoginProps = CloudflareLoginProps;
|
|
87
|
+
/**
|
|
88
|
+
* The wrangler {@link CliDescriptor}: TOML files under wrangler's global config
|
|
89
|
+
* directory, wrangler's OAuth app / consent pages, the `"wrangler"` keyring
|
|
90
|
+
* service, and wrangler-worded copy.
|
|
91
|
+
*/
|
|
92
|
+
declare const WRANGLER_CLI: CliDescriptor;
|
|
93
|
+
declare const readUserPreferences: () => UserPreferences;
|
|
94
|
+
declare const updateUserPreferences: (update: Partial<UserPreferences>) => void;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Build wrangler's auth layer, injecting the few consumer primitives that can't
|
|
98
|
+
* move into the shared package (logger, interactive `prompt` / `select`, and
|
|
99
|
+
* the User-Agent string).
|
|
100
|
+
*/
|
|
101
|
+
declare function createWranglerAuth(ctx: AuthContext): CloudflareAuth;
|
|
102
|
+
/** Consumer primitives {@link createWranglerProfileStore} needs. */
|
|
103
|
+
interface WranglerProfileStoreContext {
|
|
104
|
+
logger: OAuthFlowContext["logger"];
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Build wrangler's {@link ProfileStore} (TOML `.toml` / `.enc` files under the
|
|
108
|
+
* global config dir), bound to wrangler's config path, keyring service, and
|
|
109
|
+
* TOML format.
|
|
110
|
+
*/
|
|
111
|
+
declare function createWranglerProfileStore(ctx: WranglerProfileStoreContext): ProfileStore;
|
|
112
|
+
/**
|
|
113
|
+
* Apply and persist the global keyring-storage preference. Shared by
|
|
114
|
+
* `wrangler auth keyring enable|disable` and `wrangler login --use-keyring` /
|
|
115
|
+
* `--no-use-keyring`.
|
|
116
|
+
*/
|
|
117
|
+
declare function setKeyringPreference(enabled: boolean, ctx: KeyringPreferenceContext): SetKeyringPreferenceResult;
|
|
118
|
+
|
|
119
|
+
export { DefaultScopeKeys, DefaultScopes, KeyringPreferenceContext, OAUTH_CALLBACK_URL, type Scope, SetKeyringPreferenceResult, UserPreferences, WRANGLER_CLI, WRANGLER_KEYRING_SERVICE_NAME, type WranglerAuth, type WranglerAuthContext, type WranglerLoginProps, type WranglerProfileStoreContext, createTomlFileStorage, createWranglerAuth, createWranglerProfileStore, defaultAuthConfigStorage, getAuthConfigFilePath, getClientIdFromEnv, getEncryptedAuthConfigFilePath, readAuthConfigFile, readUserPreferences, setKeyringPreference, setLoginScopeKeys, updateUserPreferences, validateScopeKeys, writeAuthConfigFile };
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { createAuthConfigFileHelpers, createPreferences, createKeyringPreference, createFileStorage, createCloudflareAuth, createCloudflareProfileStore } from '../chunk-WJE5I5WS.mjs';
|
|
2
|
+
import '../chunk-FX4KV7FS.mjs';
|
|
3
|
+
import { __name } from '../chunk-O6YSETKJ.mjs';
|
|
4
|
+
import { getEnvironmentVariableFactory, getCloudflareApiEnvironmentFromEnv, getGlobalConfigPath, configFileName } from '@cloudflare/workers-utils';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
|
|
7
|
+
// src/core/scopes.ts
|
|
8
|
+
var DefaultScopes = {
|
|
9
|
+
"account:read": "See your account info such as account details, analytics, and memberships.",
|
|
10
|
+
"user:read": "See your user info such as name, email address, and account memberships.",
|
|
11
|
+
"workers:write": "See and change Cloudflare Workers data such as zones, KV storage, namespaces, scripts, and routes.",
|
|
12
|
+
"workers_kv:write": "See and change Cloudflare Workers KV Storage data such as keys and namespaces.",
|
|
13
|
+
"workers_routes:write": "See and change Cloudflare Workers data such as filters and routes.",
|
|
14
|
+
"workers_scripts:write": "See and change Cloudflare Workers scripts, durable objects, subdomains, triggers, and tail data.",
|
|
15
|
+
"workers_tail:read": "See Cloudflare Workers tail and script data.",
|
|
16
|
+
"d1:write": "See and change D1 Databases.",
|
|
17
|
+
"pages:write": "See and change Cloudflare Pages projects, settings and deployments.",
|
|
18
|
+
"zone:read": "Grants read level access to account zone.",
|
|
19
|
+
"ssl_certs:write": "See and manage mTLS certificates for your account",
|
|
20
|
+
"ai:write": "See and change Workers AI catalog and assets",
|
|
21
|
+
"ai-search:write": "See and change AI Search data",
|
|
22
|
+
"ai-search:run": "Run search queries on your AI Search instances",
|
|
23
|
+
"websearch.run": "Run search queries against Cloudflare Web Search",
|
|
24
|
+
"agent-memory:write": "See and change Agent Memory data such as keys and namespaces.",
|
|
25
|
+
"queues:write": "See and change Cloudflare Queues settings and data",
|
|
26
|
+
"pipelines:write": "See and change Cloudflare Pipelines configurations and data",
|
|
27
|
+
"secrets_store:write": "See and change secrets + stores within the Secrets Store",
|
|
28
|
+
"artifacts:write": "See and change Cloudflare Artifacts data such as registries and artifacts",
|
|
29
|
+
"flagship:write": "See and change Flagship feature flags and apps",
|
|
30
|
+
"containers:write": "Manage Workers Containers",
|
|
31
|
+
"cloudchamber:write": "Manage Cloudchamber",
|
|
32
|
+
"connectivity:admin": "See, change, and bind to Connectivity Directory services, including creating services targeting Cloudflare Tunnel.",
|
|
33
|
+
"email_routing:write": "See and change Email Routing settings, rules, and destination addresses.",
|
|
34
|
+
"email_sending:write": "See and change Email Sending settings and configuration.",
|
|
35
|
+
"browser:write": "See and manage Browser Run sessions",
|
|
36
|
+
"challenge-widgets.write": "See and change Turnstile widgets"
|
|
37
|
+
};
|
|
38
|
+
var DefaultScopeKeys = Object.keys(DefaultScopes);
|
|
39
|
+
function setLoginScopeKeys(scopes) {
|
|
40
|
+
DefaultScopeKeys = scopes;
|
|
41
|
+
}
|
|
42
|
+
__name(setLoginScopeKeys, "setLoginScopeKeys");
|
|
43
|
+
function validateScopeKeys(scopes) {
|
|
44
|
+
return scopes.every((scope) => scope in DefaultScopes);
|
|
45
|
+
}
|
|
46
|
+
__name(validateScopeKeys, "validateScopeKeys");
|
|
47
|
+
|
|
48
|
+
// src/wrangler/constants.ts
|
|
49
|
+
var WRANGLER_KEYRING_SERVICE_NAME = "wrangler";
|
|
50
|
+
var WRANGLER_CLI_NAME = "wrangler";
|
|
51
|
+
var OAUTH_CALLBACK_URL = "http://localhost:8976/oauth/callback";
|
|
52
|
+
var WRANGLER_CONSENT_PAGES = {
|
|
53
|
+
granted: {
|
|
54
|
+
url: "https://welcome.developers.workers.dev/wrangler-oauth-consent-granted"
|
|
55
|
+
},
|
|
56
|
+
denied: {
|
|
57
|
+
url: "https://welcome.developers.workers.dev/wrangler-oauth-consent-denied",
|
|
58
|
+
error: "Error: Consent denied. You must grant consent to Wrangler in order to login.\nIf you don't want to do this consider passing an API token via the `CLOUDFLARE_API_TOKEN` environment variable"
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var getClientIdFromEnv = getEnvironmentVariableFactory({
|
|
62
|
+
variableName: "WRANGLER_CLIENT_ID",
|
|
63
|
+
defaultValue: /* @__PURE__ */ __name(() => getCloudflareApiEnvironmentFromEnv() === "staging" ? "4b2ea6cc-9421-4761-874b-ce550e0e3def" : "54d11594-84e4-41aa-b438-e81b8fa78ee7", "defaultValue")
|
|
64
|
+
});
|
|
65
|
+
function getTemporaryAccountConfigFile() {
|
|
66
|
+
const environment = getCloudflareApiEnvironmentFromEnv();
|
|
67
|
+
return environment === "production" ? "wrangler-temporary-account.toml" : `wrangler-temporary-account.${environment}.toml`;
|
|
68
|
+
}
|
|
69
|
+
__name(getTemporaryAccountConfigFile, "getTemporaryAccountConfigFile");
|
|
70
|
+
function getTemporaryPreviewAccountConfigPath() {
|
|
71
|
+
return path.join(getGlobalConfigPath(), getTemporaryAccountConfigFile());
|
|
72
|
+
}
|
|
73
|
+
__name(getTemporaryPreviewAccountConfigPath, "getTemporaryPreviewAccountConfigPath");
|
|
74
|
+
function createTomlFileStorage(getPath) {
|
|
75
|
+
return createFileStorage("toml", getPath);
|
|
76
|
+
}
|
|
77
|
+
__name(createTomlFileStorage, "createTomlFileStorage");
|
|
78
|
+
var {
|
|
79
|
+
getAuthConfigFilePath,
|
|
80
|
+
getEncryptedAuthConfigFilePath,
|
|
81
|
+
defaultAuthConfigStorage,
|
|
82
|
+
readAuthConfigFile,
|
|
83
|
+
writeAuthConfigFile
|
|
84
|
+
} = createAuthConfigFileHelpers({
|
|
85
|
+
getConfigPath: getGlobalConfigPath,
|
|
86
|
+
format: "toml"
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// src/wrangler/index.ts
|
|
90
|
+
var WRANGLER_CLI = {
|
|
91
|
+
cliName: WRANGLER_CLI_NAME,
|
|
92
|
+
commands: {
|
|
93
|
+
login: "wrangler login",
|
|
94
|
+
whoami: "wrangler whoami",
|
|
95
|
+
createProfile: "wrangler auth create"
|
|
96
|
+
},
|
|
97
|
+
keyringServiceName: WRANGLER_KEYRING_SERVICE_NAME,
|
|
98
|
+
clientId: getClientIdFromEnv,
|
|
99
|
+
consent: WRANGLER_CONSENT_PAGES,
|
|
100
|
+
redirectUri: OAUTH_CALLBACK_URL,
|
|
101
|
+
allowGlobalAuthKey: true,
|
|
102
|
+
getConfigPath: getGlobalConfigPath,
|
|
103
|
+
getTemporaryAccountConfigPath: getTemporaryPreviewAccountConfigPath,
|
|
104
|
+
fileFormat: "toml",
|
|
105
|
+
accountCachePrefix: "wrangler-account",
|
|
106
|
+
getConfigFileLabel: /* @__PURE__ */ __name(() => configFileName(void 0), "getConfigFileLabel"),
|
|
107
|
+
// A getter so any reassignment of the live `DefaultScopeKeys` binding is
|
|
108
|
+
// observed rather than captured at wiring time.
|
|
109
|
+
getDefaultScopeKeys: /* @__PURE__ */ __name(() => DefaultScopeKeys, "getDefaultScopeKeys")
|
|
110
|
+
};
|
|
111
|
+
var wranglerPreferences = createPreferences(getGlobalConfigPath);
|
|
112
|
+
var { readUserPreferences, updateUserPreferences } = wranglerPreferences;
|
|
113
|
+
function createWranglerAuth(ctx) {
|
|
114
|
+
return createCloudflareAuth(WRANGLER_CLI, ctx);
|
|
115
|
+
}
|
|
116
|
+
__name(createWranglerAuth, "createWranglerAuth");
|
|
117
|
+
function createWranglerProfileStore(ctx) {
|
|
118
|
+
return createCloudflareProfileStore({
|
|
119
|
+
logger: ctx.logger,
|
|
120
|
+
getConfigPath: getGlobalConfigPath,
|
|
121
|
+
keyringServiceName: WRANGLER_KEYRING_SERVICE_NAME,
|
|
122
|
+
format: "toml"
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
__name(createWranglerProfileStore, "createWranglerProfileStore");
|
|
126
|
+
var wranglerKeyringPreference = createKeyringPreference({
|
|
127
|
+
loginCommand: WRANGLER_CLI.commands.login,
|
|
128
|
+
createProfileCommand: WRANGLER_CLI.commands.createProfile,
|
|
129
|
+
keyringServiceName: WRANGLER_KEYRING_SERVICE_NAME,
|
|
130
|
+
getConfigPath: getGlobalConfigPath,
|
|
131
|
+
format: "toml",
|
|
132
|
+
preferences: wranglerPreferences
|
|
133
|
+
});
|
|
134
|
+
function setKeyringPreference(enabled, ctx) {
|
|
135
|
+
return wranglerKeyringPreference.setKeyringPreference(enabled, ctx);
|
|
136
|
+
}
|
|
137
|
+
__name(setKeyringPreference, "setKeyringPreference");
|
|
138
|
+
|
|
139
|
+
export { DefaultScopeKeys, DefaultScopes, OAUTH_CALLBACK_URL, WRANGLER_CLI, WRANGLER_KEYRING_SERVICE_NAME, createTomlFileStorage, createWranglerAuth, createWranglerProfileStore, defaultAuthConfigStorage, getAuthConfigFilePath, getClientIdFromEnv, getEncryptedAuthConfigFilePath, readAuthConfigFile, readUserPreferences, setKeyringPreference, setLoginScopeKeys, updateUserPreferences, validateScopeKeys, writeAuthConfigFile };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudflare/workers-auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Internal OAuth 2.0 + PKCE flow for Cloudflare CLIs. Not intended for external use — APIs may change without notice.",
|
|
5
5
|
"homepage": "https://github.com/cloudflare/workers-sdk/tree/main/packages/workers-auth#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -22,6 +22,14 @@
|
|
|
22
22
|
"import": "./dist/index.mjs",
|
|
23
23
|
"types": "./dist/index.d.mts"
|
|
24
24
|
},
|
|
25
|
+
"./wrangler": {
|
|
26
|
+
"import": "./dist/wrangler/index.mjs",
|
|
27
|
+
"types": "./dist/wrangler/index.d.mts"
|
|
28
|
+
},
|
|
29
|
+
"./cf": {
|
|
30
|
+
"import": "./dist/cf/index.mjs",
|
|
31
|
+
"types": "./dist/cf/index.d.mts"
|
|
32
|
+
},
|
|
25
33
|
"./test-helpers": {
|
|
26
34
|
"import": "./dist/test-helpers/index.mjs",
|
|
27
35
|
"types": "./dist/test-helpers/index.d.mts"
|
|
@@ -29,12 +37,13 @@
|
|
|
29
37
|
},
|
|
30
38
|
"dependencies": {
|
|
31
39
|
"undici": "7.28.0",
|
|
32
|
-
"@cloudflare/workers-utils": "0.
|
|
40
|
+
"@cloudflare/workers-utils": "0.27.0"
|
|
33
41
|
},
|
|
34
42
|
"devDependencies": {
|
|
35
43
|
"@types/node": "22.15.17",
|
|
36
44
|
"@vitest/ui": "4.1.0",
|
|
37
45
|
"concurrently": "^8.2.2",
|
|
46
|
+
"date-fns": "^4.1.0",
|
|
38
47
|
"msw": "2.12.4",
|
|
39
48
|
"smol-toml": "1.5.2",
|
|
40
49
|
"ts-dedent": "^2.2.0",
|