@cloudflare/workers-auth 0.1.1 → 0.3.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/index.d.mts +200 -227
- package/dist/index.mjs +474 -1293
- package/dist/metafile-esm.json +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ApiCredentials, ComplianceConfig } from '@cloudflare/workers-utils';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Pluggable persistence for a typed config blob
|
|
5
|
+
*/
|
|
6
|
+
interface ConfigStorage<T> {
|
|
7
|
+
/**
|
|
8
|
+
* Read and parse the stored config.
|
|
9
|
+
* @throws if the backing store is missing or cannot be parsed.
|
|
10
|
+
*/
|
|
11
|
+
read(): T;
|
|
12
|
+
/** Serialize and persist the config. */
|
|
13
|
+
write(config: T): void;
|
|
14
|
+
/** Remove the backing store; returns whether anything existed beforehand. */
|
|
15
|
+
clear(): boolean;
|
|
16
|
+
/** Human-readable location of the backing store, for display and warnings. */
|
|
17
|
+
path(): string;
|
|
18
|
+
}
|
|
2
19
|
|
|
3
20
|
/**
|
|
4
21
|
* The data that may be read from the on-disk user auth config file.
|
|
@@ -11,29 +28,24 @@ interface UserAuthConfig {
|
|
|
11
28
|
/** @deprecated - this field was only provided by the deprecated v1 `wrangler config` command. */
|
|
12
29
|
api_token?: string;
|
|
13
30
|
}
|
|
31
|
+
type AuthConfigStorage = ConfigStorage<UserAuthConfig>;
|
|
32
|
+
|
|
14
33
|
/**
|
|
15
|
-
*
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Reads the user auth config from disk.
|
|
32
|
-
*
|
|
33
|
-
* @throws if the file does not exist or cannot be parsed as TOML. Callers
|
|
34
|
-
* typically catch this and treat the failure as "not logged in via local OAuth".
|
|
35
|
-
*/
|
|
36
|
-
declare function readAuthConfigFile(): UserAuthConfig;
|
|
34
|
+
* A short-lived "temporary preview account"
|
|
35
|
+
*/
|
|
36
|
+
type TemporaryPreviewAccount = {
|
|
37
|
+
account: {
|
|
38
|
+
id: string;
|
|
39
|
+
name: string;
|
|
40
|
+
apiToken: string;
|
|
41
|
+
expiresAt: string;
|
|
42
|
+
};
|
|
43
|
+
claim: {
|
|
44
|
+
url: string;
|
|
45
|
+
expiresAt: string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
type TemporaryAccountStorage = ConfigStorage<TemporaryPreviewAccount>;
|
|
37
49
|
|
|
38
50
|
interface GenerateAuthUrlProps {
|
|
39
51
|
authUrl: string;
|
|
@@ -41,8 +53,8 @@ interface GenerateAuthUrlProps {
|
|
|
41
53
|
scopes: string[];
|
|
42
54
|
stateQueryParam: string;
|
|
43
55
|
codeChallenge: string;
|
|
56
|
+
redirectUri: string;
|
|
44
57
|
}
|
|
45
|
-
declare const OAUTH_CALLBACK_URL = "http://localhost:8976/oauth/callback";
|
|
46
58
|
/**
|
|
47
59
|
* Build the OAuth 2.0 authorize URL for the Cloudflare auth endpoint.
|
|
48
60
|
*
|
|
@@ -50,7 +62,7 @@ declare const OAUTH_CALLBACK_URL = "http://localhost:8976/oauth/callback";
|
|
|
50
62
|
* substitute a deterministic implementation when a stable URL is needed
|
|
51
63
|
* (e.g. for snapshot testing).
|
|
52
64
|
*/
|
|
53
|
-
declare const generateAuthUrl: ({ authUrl, clientId, scopes, stateQueryParam, codeChallenge, }: GenerateAuthUrlProps) => string;
|
|
65
|
+
declare const generateAuthUrl: ({ authUrl, clientId, scopes, stateQueryParam, codeChallenge, redirectUri, }: GenerateAuthUrlProps) => string;
|
|
54
66
|
|
|
55
67
|
/**
|
|
56
68
|
* Generates random state to be passed for anti-csrf.
|
|
@@ -61,6 +73,38 @@ declare const generateAuthUrl: ({ authUrl, clientId, scopes, stateQueryParam, co
|
|
|
61
73
|
*/
|
|
62
74
|
declare function generateRandomState(lengthOfState: number): string;
|
|
63
75
|
|
|
76
|
+
/**
|
|
77
|
+
* The dependencies the OAuth flow needs to mint/reuse a short-lived "temporary
|
|
78
|
+
* preview account"
|
|
79
|
+
*/
|
|
80
|
+
interface OAuthFlowTemporaryContext {
|
|
81
|
+
/** Persistence backend for the cached temporary preview account. */
|
|
82
|
+
storage: TemporaryAccountStorage;
|
|
83
|
+
/**
|
|
84
|
+
* Hook to customise the terms-acceptance interactive prompt
|
|
85
|
+
* - question: the question to ask a user in interactive mode.
|
|
86
|
+
* return answer === "yes" (must be the literal string)
|
|
87
|
+
* - notice: the notice to print on stderr if in non-interactive mode
|
|
88
|
+
* always return true
|
|
89
|
+
*/
|
|
90
|
+
prompt: (question: string, notice: string) => Promise<boolean>;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The branded OAuth consent pages the provider redirects the browser to after
|
|
94
|
+
* the user grants or denies consent.
|
|
95
|
+
*/
|
|
96
|
+
interface OAuthConsentPages {
|
|
97
|
+
/** Redirect target shown after the user grants consent. */
|
|
98
|
+
granted: {
|
|
99
|
+
url: string;
|
|
100
|
+
};
|
|
101
|
+
/** Redirect target shown after the user denies consent, plus the error
|
|
102
|
+
* surfaced to the terminal. */
|
|
103
|
+
denied: {
|
|
104
|
+
url: string;
|
|
105
|
+
error: string;
|
|
106
|
+
};
|
|
107
|
+
}
|
|
64
108
|
/**
|
|
65
109
|
* Subset of the wrangler `logger` singleton used by the OAuth flow.
|
|
66
110
|
* Consumers pass in an implementation that maps to their own logging surface.
|
|
@@ -107,6 +151,36 @@ interface OAuthFlowContext {
|
|
|
107
151
|
* cache).
|
|
108
152
|
*/
|
|
109
153
|
purgeOnLoginOrLogout?: () => void;
|
|
154
|
+
/**
|
|
155
|
+
* The OAuth client ID identifying the consuming CLI to the Cloudflare OAuth
|
|
156
|
+
* server. Consumer-specific (each CLI registers its own OAuth app), so it is
|
|
157
|
+
* required. Pass a function to resolve it lazily — e.g. so an env-var read at
|
|
158
|
+
* call time can switch between production and staging apps.
|
|
159
|
+
*/
|
|
160
|
+
clientId: string | (() => string);
|
|
161
|
+
/**
|
|
162
|
+
* The branded consent pages the provider redirects to after the user grants
|
|
163
|
+
* or denies consent.
|
|
164
|
+
*/
|
|
165
|
+
consent: OAuthConsentPages;
|
|
166
|
+
/**
|
|
167
|
+
* The `redirect_uri` registered on the consumer's OAuth app
|
|
168
|
+
*/
|
|
169
|
+
redirectUri: string;
|
|
170
|
+
/**
|
|
171
|
+
* Persistence backend for the stored auth config.
|
|
172
|
+
*/
|
|
173
|
+
storage: AuthConfigStorage;
|
|
174
|
+
/**
|
|
175
|
+
* Whether the flow's credential resolvers (`getAPIToken` / `requireApiToken`)
|
|
176
|
+
* should honour the global API key + email pair in addition to scoped API
|
|
177
|
+
* tokens.
|
|
178
|
+
*/
|
|
179
|
+
allowGlobalAuthKey: boolean;
|
|
180
|
+
/**
|
|
181
|
+
* Dependencies for minting/reusing a temporary preview account.
|
|
182
|
+
*/
|
|
183
|
+
temporary: OAuthFlowTemporaryContext | undefined;
|
|
110
184
|
/**
|
|
111
185
|
* Override the OAuth authorize URL generator. Used by tests to produce a
|
|
112
186
|
* deterministic URL for snapshot testing. Defaults to the standard
|
|
@@ -121,6 +195,35 @@ interface OAuthFlowContext {
|
|
|
121
195
|
generateRandomState?: typeof generateRandomState;
|
|
122
196
|
}
|
|
123
197
|
|
|
198
|
+
/** `CLOUDFLARE_API_TOKEN` (legacy alias `CF_API_TOKEN`): a scoped API token. */
|
|
199
|
+
declare const getCloudflareAPITokenFromEnv: () => string | undefined;
|
|
200
|
+
/** `CLOUDFLARE_API_KEY` (legacy alias `CF_API_KEY`): the global API key. */
|
|
201
|
+
declare const getCloudflareGlobalAuthKeyFromEnv: () => string | undefined;
|
|
202
|
+
/** `CLOUDFLARE_EMAIL` (legacy alias `CF_EMAIL`): the account email, paired with
|
|
203
|
+
* the global API key. */
|
|
204
|
+
declare const getCloudflareGlobalAuthEmailFromEnv: () => string | undefined;
|
|
205
|
+
interface GetAuthFromEnvOptions {
|
|
206
|
+
/**
|
|
207
|
+
* Whether to honour the global API key + email pair
|
|
208
|
+
* (`CLOUDFLARE_API_KEY` + `CLOUDFLARE_EMAIL`, surfaced as
|
|
209
|
+
* `X-Auth-Key`/`X-Auth-Email`). Defaults to `true` (Wrangler's behaviour).
|
|
210
|
+
* CLIs that only support scoped API tokens / OAuth should pass `false`.
|
|
211
|
+
*/
|
|
212
|
+
allowGlobalAuthKey?: boolean;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Resolve Cloudflare API credentials from environment variables.
|
|
216
|
+
*
|
|
217
|
+
* Priority (highest to lowest), matching Wrangler's historical order:
|
|
218
|
+
* 1. Global API key + email (`CLOUDFLARE_API_KEY` + `CLOUDFLARE_EMAIL`) —
|
|
219
|
+
* only when `allowGlobalAuthKey` is `true`.
|
|
220
|
+
* 2. API token (`CLOUDFLARE_API_TOKEN`).
|
|
221
|
+
*
|
|
222
|
+
* @returns the resolved credentials, or `undefined` when no env credentials
|
|
223
|
+
* are present.
|
|
224
|
+
*/
|
|
225
|
+
declare function getAuthFromEnv(options?: GetAuthFromEnvOptions): ApiCredentials | undefined;
|
|
226
|
+
|
|
124
227
|
/**
|
|
125
228
|
* Clear internal caches. Exported for use in tests only.
|
|
126
229
|
*/
|
|
@@ -152,37 +255,7 @@ declare function getAccessHeaders(domain: string, options: {
|
|
|
152
255
|
logger: OAuthFlowLogger;
|
|
153
256
|
isNonInteractiveOrCI: () => boolean;
|
|
154
257
|
}): Promise<Record<string, string>>;
|
|
155
|
-
/**
|
|
156
|
-
* Get headers needed to authenticate with the Cloudflare OAuth auth domain
|
|
157
|
-
* (the OAuth `WRANGLER_AUTH_DOMAIN`, which is `dash.cloudflare.com` by default
|
|
158
|
-
* and `dash.staging.cloudflare.com` in staging).
|
|
159
|
-
*
|
|
160
|
-
* Checks `WRANGLER_CF_AUTHORIZATION_TOKEN` first, then falls back to
|
|
161
|
-
* {@link getAccessHeaders} against the configured auth domain.
|
|
162
|
-
*/
|
|
163
|
-
declare function getCloudflareAccessHeaders(options: {
|
|
164
|
-
logger: OAuthFlowLogger;
|
|
165
|
-
isNonInteractiveOrCI: () => boolean;
|
|
166
|
-
}): Promise<Record<string, string>>;
|
|
167
258
|
|
|
168
|
-
/**
|
|
169
|
-
* `WRANGLER_CLIENT_ID` is a UUID that is used to identify Wrangler
|
|
170
|
-
* to the Cloudflare APIs.
|
|
171
|
-
*
|
|
172
|
-
* Normally you should not need to set this explicitly.
|
|
173
|
-
* If you want to switch to the staging environment set the
|
|
174
|
-
* `WRANGLER_API_ENVIRONMENT=staging` environment variable instead.
|
|
175
|
-
*/
|
|
176
|
-
declare const getClientIdFromEnv: () => string;
|
|
177
|
-
/**
|
|
178
|
-
* `WRANGLER_AUTH_DOMAIN` is the URL base domain that is used
|
|
179
|
-
* to access OAuth URLs for the Cloudflare APIs.
|
|
180
|
-
*
|
|
181
|
-
* Normally you should not need to set this explicitly.
|
|
182
|
-
* If you want to switch to the staging environment set the
|
|
183
|
-
* `WRANGLER_API_ENVIRONMENT=staging` environment variable instead.
|
|
184
|
-
*/
|
|
185
|
-
declare const getAuthDomainFromEnv: () => string;
|
|
186
259
|
/**
|
|
187
260
|
* `WRANGLER_AUTH_URL` is the path that is used to access OAuth
|
|
188
261
|
* for the Cloudflare APIs.
|
|
@@ -192,132 +265,33 @@ declare const getAuthDomainFromEnv: () => string;
|
|
|
192
265
|
* `WRANGLER_API_ENVIRONMENT=staging` environment variable instead.
|
|
193
266
|
*/
|
|
194
267
|
declare const getAuthUrlFromEnv: () => string;
|
|
195
|
-
/**
|
|
196
|
-
* `WRANGLER_TOKEN_URL` is the path that is used to exchange an OAuth
|
|
197
|
-
* token for an API token.
|
|
198
|
-
*
|
|
199
|
-
* Normally you should not need to set this explicitly.
|
|
200
|
-
* If you want to switch to the staging environment set the
|
|
201
|
-
* `WRANGLER_API_ENVIRONMENT=staging` environment variable instead.
|
|
202
|
-
*/
|
|
203
|
-
declare const getTokenUrlFromEnv: () => string;
|
|
204
|
-
/**
|
|
205
|
-
* `WRANGLER_REVOKE_URL` is the path that is used to exchange an OAuth
|
|
206
|
-
* refresh token for a new OAuth token.
|
|
207
|
-
*
|
|
208
|
-
* Normally you should not need to set this explicitly.
|
|
209
|
-
* If you want to switch to the staging environment set the
|
|
210
|
-
* `WRANGLER_API_ENVIRONMENT=staging` environment variable instead.
|
|
211
|
-
*/
|
|
212
|
-
declare const getRevokeUrlFromEnv: () => string;
|
|
213
|
-
/**
|
|
214
|
-
* `CLOUDFLARE_ACCESS_CLIENT_ID` is the Client ID of a Cloudflare Access Service Token.
|
|
215
|
-
* Used together with `CLOUDFLARE_ACCESS_CLIENT_SECRET` to authenticate with
|
|
216
|
-
* Access-protected domains in non-interactive environments (e.g. CI).
|
|
217
|
-
*
|
|
218
|
-
* @see https://developers.cloudflare.com/cloudflare-one/access-controls/service-credentials/service-tokens/
|
|
219
|
-
*/
|
|
220
|
-
declare const getAccessClientIdFromEnv: () => string | undefined;
|
|
221
|
-
/**
|
|
222
|
-
* `CLOUDFLARE_ACCESS_CLIENT_SECRET` is the Client Secret of a Cloudflare Access Service Token.
|
|
223
|
-
* Used together with `CLOUDFLARE_ACCESS_CLIENT_ID` to authenticate with
|
|
224
|
-
* Access-protected domains in non-interactive environments (e.g. CI).
|
|
225
|
-
*
|
|
226
|
-
* @see https://developers.cloudflare.com/cloudflare-one/access-controls/service-credentials/service-tokens/
|
|
227
|
-
*/
|
|
228
|
-
declare const getAccessClientSecretFromEnv: () => string | undefined;
|
|
229
|
-
/**
|
|
230
|
-
* `WRANGLER_CF_AUTHORIZATION_TOKEN` is an explicit `CF_Authorization` cookie value
|
|
231
|
-
* used to authenticate against the OAuth auth domain when it is Access-protected
|
|
232
|
-
* (typically staging). When set, the OAuth flow skips Access detection and uses
|
|
233
|
-
* this token directly.
|
|
234
|
-
*/
|
|
235
|
-
declare const getCfAuthorizationTokenFromEnv: () => string | undefined;
|
|
236
268
|
|
|
237
269
|
/**
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
* Instances may carry the structured details from the OAuth provider's
|
|
241
|
-
* `error`, `error_description` and `error_uri` query parameters (RFC 6749
|
|
242
|
-
* §4.1.2.1) so callers can render them — see {@link toErrorClass}.
|
|
243
|
-
*/
|
|
244
|
-
declare class ErrorOAuth2 extends UserError {
|
|
245
|
-
/** The OAuth `error` code returned by the provider (e.g. `invalid_scope`). */
|
|
246
|
-
code?: string;
|
|
247
|
-
/** The OAuth `error_description` returned by the provider, if any. */
|
|
248
|
-
description?: string;
|
|
249
|
-
/** The OAuth `error_uri` returned by the provider, if any. */
|
|
250
|
-
uri?: string;
|
|
251
|
-
toString(): string;
|
|
252
|
-
}
|
|
253
|
-
declare class ErrorUnknown extends ErrorOAuth2 {
|
|
254
|
-
toString(): string;
|
|
255
|
-
}
|
|
256
|
-
declare class ErrorNoAuthCode extends ErrorOAuth2 {
|
|
257
|
-
toString(): string;
|
|
258
|
-
}
|
|
259
|
-
declare class ErrorInvalidReturnedStateParam extends ErrorOAuth2 {
|
|
260
|
-
toString(): string;
|
|
261
|
-
}
|
|
262
|
-
declare class ErrorInvalidJson extends ErrorOAuth2 {
|
|
263
|
-
toString(): string;
|
|
264
|
-
}
|
|
265
|
-
declare class ErrorInvalidScope extends ErrorOAuth2 {
|
|
266
|
-
toString(): string;
|
|
267
|
-
}
|
|
268
|
-
declare class ErrorInvalidRequest extends ErrorOAuth2 {
|
|
269
|
-
toString(): string;
|
|
270
|
-
}
|
|
271
|
-
declare class ErrorInvalidToken extends ErrorOAuth2 {
|
|
272
|
-
toString(): string;
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Possible authorization grant errors given by the redirection from the
|
|
276
|
-
* authorization server.
|
|
277
|
-
*/
|
|
278
|
-
declare class ErrorAuthenticationGrant extends ErrorOAuth2 {
|
|
279
|
-
toString(): string;
|
|
280
|
-
}
|
|
281
|
-
declare class ErrorUnauthorizedClient extends ErrorAuthenticationGrant {
|
|
282
|
-
toString(): string;
|
|
283
|
-
}
|
|
284
|
-
declare class ErrorAccessDenied extends ErrorAuthenticationGrant {
|
|
285
|
-
toString(): string;
|
|
286
|
-
}
|
|
287
|
-
declare class ErrorUnsupportedResponseType extends ErrorAuthenticationGrant {
|
|
288
|
-
toString(): string;
|
|
289
|
-
}
|
|
290
|
-
declare class ErrorServerError extends ErrorAuthenticationGrant {
|
|
291
|
-
toString(): string;
|
|
292
|
-
}
|
|
293
|
-
declare class ErrorTemporarilyUnavailable extends ErrorAuthenticationGrant {
|
|
294
|
-
toString(): string;
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* A list of possible access token response errors.
|
|
270
|
+
* Reason why {@link OAuthFlowAPI.loginOrRefreshIfRequired} could not
|
|
271
|
+
* authenticate the user.
|
|
298
272
|
*/
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
declare class ErrorUnsupportedGrantType extends ErrorAccessTokenResponse {
|
|
309
|
-
toString(): string;
|
|
310
|
-
}
|
|
273
|
+
type LoginOrRefreshFailureReason =
|
|
274
|
+
/** no stored credentials and the environment is non-interactive (CI, piped stdin, etc.) so a browser login cannot be started. */
|
|
275
|
+
"no-credentials-non-interactive"
|
|
276
|
+
/** stored credentials and the interactive login attempt was unsuccessful (user cancelled, etc.). */
|
|
277
|
+
| "no-credentials-login-failed"
|
|
278
|
+
/** the stored token has expired, refresh failed, and the environment is non-interactive so a browser login cannot be started. */
|
|
279
|
+
| "token-expired-non-interactive"
|
|
280
|
+
/** the stored token has expired, refresh failed, and the interactive login attempt was unsuccessful. */
|
|
281
|
+
| "token-expired-login-failed";
|
|
311
282
|
/**
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
* render them on the browser-facing error page.
|
|
283
|
+
* Discriminated union returned by {@link OAuthFlowAPI.loginOrRefreshIfRequired}.
|
|
284
|
+
*
|
|
285
|
+
* When `loggedIn` is `true` the caller can proceed. When `false`, `reason`
|
|
286
|
+
* describes why authentication failed so the caller can surface a
|
|
287
|
+
* targeted error message.
|
|
318
288
|
*/
|
|
319
|
-
|
|
320
|
-
|
|
289
|
+
type LoginOrRefreshResult = {
|
|
290
|
+
loggedIn: true;
|
|
291
|
+
} | {
|
|
292
|
+
loggedIn: false;
|
|
293
|
+
reason: LoginOrRefreshFailureReason;
|
|
294
|
+
};
|
|
321
295
|
/**
|
|
322
296
|
* Options for an interactive OAuth login.
|
|
323
297
|
*/
|
|
@@ -369,11 +343,12 @@ interface OAuthFlowAPI {
|
|
|
369
343
|
* Scopes are required in case an interactive login is triggered — the
|
|
370
344
|
* consumer's scope catalog lives outside this package.
|
|
371
345
|
*
|
|
372
|
-
* @returns `true` when the user is
|
|
373
|
-
* present)
|
|
374
|
-
*
|
|
346
|
+
* @returns `{ loggedIn: true }` when the user is authenticated (or env
|
|
347
|
+
* credentials are present). When authentication fails, returns
|
|
348
|
+
* `{ loggedIn: false, reason }` describing why — see
|
|
349
|
+
* {@link LoginOrRefreshFailureReason}.
|
|
375
350
|
*/
|
|
376
|
-
loginOrRefreshIfRequired(props: LoginProps): Promise<
|
|
351
|
+
loginOrRefreshIfRequired(props: LoginProps): Promise<LoginOrRefreshResult>;
|
|
377
352
|
/**
|
|
378
353
|
* Read the OAuth access token from local state, refreshing it first if
|
|
379
354
|
* needed. Returns `undefined` when there is no stored OAuth token or the
|
|
@@ -384,17 +359,45 @@ interface OAuthFlowAPI {
|
|
|
384
359
|
*/
|
|
385
360
|
getOAuthTokenFromLocalState(): Promise<string | undefined>;
|
|
386
361
|
/**
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
362
|
+
* Resolve API credentials, preferring an active temporary preview account
|
|
363
|
+
* (when one has been latched via {@link activateTemporaryAccount}) over the
|
|
364
|
+
* env / stored-OAuth resolution performed by the shared credential resolver.
|
|
365
|
+
*
|
|
366
|
+
* Returns `undefined` when no credentials are available.
|
|
367
|
+
*/
|
|
368
|
+
getAPIToken(): ApiCredentials | undefined;
|
|
369
|
+
/**
|
|
370
|
+
* Like {@link getAPIToken}, but throws a `UserError` when no credentials are
|
|
371
|
+
* available.
|
|
372
|
+
*/
|
|
373
|
+
requireApiToken(): ApiCredentials;
|
|
374
|
+
/**
|
|
375
|
+
* Establish whether `--temporary` is permitted for this invocation. Called
|
|
376
|
+
* once at command dispatch by the consumer. Also drops any temporary account
|
|
377
|
+
* latched by a previous dispatch, so that — when multiple commands share a
|
|
378
|
+
* process (e.g. in tests) — each invocation starts a fresh temporary session.
|
|
379
|
+
* No-op when the flow was created without a `temporary` context.
|
|
380
|
+
*/
|
|
381
|
+
setTemporaryAllowed(allowed: boolean): void;
|
|
382
|
+
/**
|
|
383
|
+
* Whether `--temporary` is permitted for this invocation (see
|
|
384
|
+
* {@link setTemporaryAllowed}). Always `false` without a `temporary` context.
|
|
391
385
|
*/
|
|
392
|
-
|
|
386
|
+
isTemporaryAllowed(): boolean;
|
|
393
387
|
/**
|
|
394
|
-
*
|
|
395
|
-
*
|
|
388
|
+
* The temporary preview account latched for this invocation, or `undefined`.
|
|
389
|
+
* Only set after {@link activateTemporaryAccount} has run.
|
|
396
390
|
*/
|
|
397
|
-
|
|
391
|
+
getActiveTemporaryAccount(): TemporaryPreviewAccount | undefined;
|
|
392
|
+
/**
|
|
393
|
+
* The sole creator of the temporary-account latch: mint a fresh temporary
|
|
394
|
+
* preview account (or reuse a cached one), latch it for this invocation, and
|
|
395
|
+
* return it. Requires a `temporary` context.
|
|
396
|
+
*/
|
|
397
|
+
activateTemporaryAccount(): Promise<{
|
|
398
|
+
account: TemporaryPreviewAccount;
|
|
399
|
+
cached: boolean;
|
|
400
|
+
}>;
|
|
398
401
|
}
|
|
399
402
|
/**
|
|
400
403
|
* Build an instance of the OAuth flow bound to the given context.
|
|
@@ -405,35 +408,13 @@ interface OAuthFlowAPI {
|
|
|
405
408
|
*/
|
|
406
409
|
declare function createOAuthFlow(ctx: OAuthFlowContext): OAuthFlowAPI;
|
|
407
410
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
* but <= 128, **after** base64 url encoding. This means 32 code verifier bytes
|
|
412
|
-
* encoded will be 43 bytes, or 96 bytes encoded will be 128 bytes. So 96 bytes
|
|
413
|
-
* is the highest valid value that can be used.
|
|
414
|
-
*/
|
|
415
|
-
declare const RECOMMENDED_CODE_VERIFIER_LENGTH = 96;
|
|
416
|
-
/**
|
|
417
|
-
* A sensible length for the state's length, for anti-csrf.
|
|
418
|
-
*/
|
|
419
|
-
declare const RECOMMENDED_STATE_LENGTH = 32;
|
|
411
|
+
declare const TEMPORARY_TERMS_PROMPT: string;
|
|
412
|
+
declare const TEMPORARY_TERMS_NOTICE: string;
|
|
413
|
+
|
|
420
414
|
/**
|
|
421
415
|
* Character set to generate code verifier defined in rfc7636.
|
|
422
416
|
*/
|
|
423
417
|
declare const PKCE_CHARSET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~";
|
|
424
|
-
interface PKCECodes {
|
|
425
|
-
codeChallenge: string;
|
|
426
|
-
codeVerifier: string;
|
|
427
|
-
}
|
|
428
|
-
/**
|
|
429
|
-
* Implements *base64url-encode* (RFC 4648 § 5) without padding, which is NOT
|
|
430
|
-
* the same as regular base64 encoding.
|
|
431
|
-
*/
|
|
432
|
-
declare function base64urlEncode(value: string): string;
|
|
433
|
-
/**
|
|
434
|
-
* Generates a code_verifier and code_challenge, as specified in rfc7636.
|
|
435
|
-
*/
|
|
436
|
-
declare function generatePKCECodes(): Promise<PKCECodes>;
|
|
437
418
|
|
|
438
419
|
interface RefreshToken {
|
|
439
420
|
value: string;
|
|
@@ -442,18 +423,6 @@ interface AccessToken {
|
|
|
442
423
|
value: string;
|
|
443
424
|
expiry: string;
|
|
444
425
|
}
|
|
445
|
-
/**
|
|
446
|
-
* Transient state that is shared across the steps of a single OAuth login flow
|
|
447
|
-
* within one Wrangler command. This state is not file-backed; it lives only for
|
|
448
|
-
* the duration of an interactive login.
|
|
449
|
-
*/
|
|
450
|
-
interface OAuthFlowState {
|
|
451
|
-
authorizationCode?: string;
|
|
452
|
-
codeChallenge?: string;
|
|
453
|
-
codeVerifier?: string;
|
|
454
|
-
hasAuthCodeBeenExchangedForAccessToken?: boolean;
|
|
455
|
-
stateQueryParam?: string;
|
|
456
|
-
}
|
|
457
426
|
/**
|
|
458
427
|
* The auth state that is stored on disk in the user auth config file (TOML).
|
|
459
428
|
* Read on demand by {@link readStoredAuthState} — never cached at module scope
|
|
@@ -481,10 +450,14 @@ interface StoredAuthState {
|
|
|
481
450
|
* @param options.warningLogger if provided, a one-time warning is emitted when a
|
|
482
451
|
* deprecated v1 `api_token` is found on disk. Pass the consumer's logger (e.g.
|
|
483
452
|
* wrangler's logger singleton) to surface this to the user.
|
|
453
|
+
* @param options.storage the persistence backend to read from, injected by the
|
|
454
|
+
* consumer (e.g. wrangler's TOML-file-on-disk storage under the global Wrangler
|
|
455
|
+
* config directory).
|
|
484
456
|
*/
|
|
485
|
-
declare function readStoredAuthState(options
|
|
457
|
+
declare function readStoredAuthState(options: {
|
|
486
458
|
configOverride?: UserAuthConfig;
|
|
487
459
|
warningLogger?: Pick<OAuthFlowLogger, "warn">;
|
|
460
|
+
storage: AuthConfigStorage;
|
|
488
461
|
}): StoredAuthState;
|
|
489
462
|
|
|
490
|
-
export { type
|
|
463
|
+
export { type AuthConfigStorage, type ConfigStorage, type LoginOrRefreshFailureReason, type LoginOrRefreshResult, type LoginProps, PKCE_CHARSET, TEMPORARY_TERMS_NOTICE, TEMPORARY_TERMS_PROMPT, type TemporaryPreviewAccount, type UserAuthConfig, clearAccessCaches, createOAuthFlow, domainUsesAccess, generateAuthUrl, generateRandomState, getAccessHeaders, getAuthFromEnv, getAuthUrlFromEnv, getCloudflareAPITokenFromEnv, getCloudflareGlobalAuthEmailFromEnv, getCloudflareGlobalAuthKeyFromEnv, readStoredAuthState };
|