@auth0/auth0-spa-js 2.4.1 → 2.6.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/README.md +1 -1
- package/dist/auth0-spa-js.development.js +298 -43
- package/dist/auth0-spa-js.development.js.map +1 -1
- package/dist/auth0-spa-js.production.esm.js +1 -1
- package/dist/auth0-spa-js.production.esm.js.map +1 -1
- package/dist/auth0-spa-js.production.js +1 -1
- package/dist/auth0-spa-js.production.js.map +1 -1
- package/dist/auth0-spa-js.worker.development.js +34 -2
- package/dist/auth0-spa-js.worker.development.js.map +1 -1
- package/dist/auth0-spa-js.worker.production.js +1 -1
- package/dist/auth0-spa-js.worker.production.js.map +1 -1
- package/dist/lib/auth0-spa-js.cjs.js +309 -44
- package/dist/lib/auth0-spa-js.cjs.js.map +1 -1
- package/dist/typings/Auth0Client.d.ts +42 -2
- package/dist/typings/Auth0Client.utils.d.ts +32 -0
- package/dist/typings/MyAccountApiClient.d.ts +92 -0
- package/dist/typings/api.d.ts +1 -1
- package/dist/typings/cache/cache-manager.d.ts +18 -1
- package/dist/typings/errors.d.ts +10 -0
- package/dist/typings/fetcher.d.ts +11 -7
- package/dist/typings/global.d.ts +97 -0
- package/dist/typings/http.d.ts +2 -2
- package/dist/typings/index.d.ts +2 -1
- package/dist/typings/transaction-manager.d.ts +15 -4
- package/dist/typings/version.d.ts +1 -1
- package/dist/typings/worker/worker.types.d.ts +1 -0
- package/package.json +1 -1
- package/src/Auth0Client.ts +282 -25
- package/src/Auth0Client.utils.ts +66 -0
- package/src/MyAccountApiClient.ts +158 -0
- package/src/api.ts +7 -1
- package/src/cache/cache-manager.ts +82 -7
- package/src/errors.ts +18 -0
- package/src/fetcher.ts +30 -18
- package/src/global.ts +112 -4
- package/src/http.ts +12 -5
- package/src/index.ts +5 -0
- package/src/transaction-manager.ts +17 -4
- package/src/utils.ts +1 -0
- package/src/version.ts +1 -1
- package/src/worker/token.worker.ts +60 -9
- package/src/worker/worker.types.ts +1 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Auth0ClientOptions, RedirectLoginOptions, PopupLoginOptions, PopupConfigOptions, RedirectLoginResult, GetTokenSilentlyOptions, GetTokenWithPopupOptions, LogoutOptions, User, IdToken, GetTokenSilentlyVerboseResponse, TokenEndpointResponse } from './global';
|
|
1
|
+
import { Auth0ClientOptions, RedirectLoginOptions, PopupLoginOptions, PopupConfigOptions, RedirectLoginResult, GetTokenSilentlyOptions, GetTokenWithPopupOptions, LogoutOptions, User, IdToken, GetTokenSilentlyVerboseResponse, TokenEndpointResponse, ConnectAccountRedirectResult, RedirectConnectAccountOptions } from './global';
|
|
2
2
|
import { CustomTokenExchangeOptions } from './TokenExchange';
|
|
3
3
|
import { Dpop } from './dpop/dpop';
|
|
4
4
|
import { Fetcher, type FetcherConfig, type CustomFetchMinimalOutput } from './fetcher';
|
|
@@ -20,6 +20,7 @@ export declare class Auth0Client {
|
|
|
20
20
|
private readonly httpTimeoutMs;
|
|
21
21
|
private readonly options;
|
|
22
22
|
private readonly userCache;
|
|
23
|
+
private readonly myAccountApi;
|
|
23
24
|
private worker?;
|
|
24
25
|
private readonly defaultOptions;
|
|
25
26
|
constructor(options: Auth0ClientOptions);
|
|
@@ -89,7 +90,30 @@ export declare class Auth0Client {
|
|
|
89
90
|
* responses from Auth0. If the response is successful, results
|
|
90
91
|
* will be valid according to their expiration times.
|
|
91
92
|
*/
|
|
92
|
-
handleRedirectCallback<TAppState = any>(url?: string): Promise<RedirectLoginResult<TAppState>>;
|
|
93
|
+
handleRedirectCallback<TAppState = any>(url?: string): Promise<RedirectLoginResult<TAppState> | ConnectAccountRedirectResult<TAppState>>;
|
|
94
|
+
/**
|
|
95
|
+
* Handles the redirect callback from the login flow.
|
|
96
|
+
*
|
|
97
|
+
* @template AppState - The application state persisted from the /authorize redirect.
|
|
98
|
+
* @param {string} authenticationResult - The parsed authentication result from the URL.
|
|
99
|
+
* @param {string} transaction - The login transaction.
|
|
100
|
+
*
|
|
101
|
+
* @returns {RedirectLoginResult} Resolves with the persisted app state.
|
|
102
|
+
* @throws {GenericError | Error} If the transaction is missing, invalid, or the code exchange fails.
|
|
103
|
+
*/
|
|
104
|
+
private _handleLoginRedirectCallback;
|
|
105
|
+
/**
|
|
106
|
+
* Handles the redirect callback from the connect account flow.
|
|
107
|
+
* This works the same as the redirect from the login flow expect it verifies the `connect_code`
|
|
108
|
+
* with the My Account API rather than the `code` with the Authorization Server.
|
|
109
|
+
*
|
|
110
|
+
* @template AppState - The application state persisted from the connect redirect.
|
|
111
|
+
* @param {string} connectResult - The parsed connect accounts result from the URL.
|
|
112
|
+
* @param {string} transaction - The login transaction.
|
|
113
|
+
* @returns {Promise<ConnectAccountRedirectResult>} The result of the My Account API, including any persisted app state.
|
|
114
|
+
* @throws {GenericError | MyAccountApiError} If the transaction is missing, invalid, or an error is returned from the My Account API.
|
|
115
|
+
*/
|
|
116
|
+
private _handleConnectAccountRedirectCallback;
|
|
93
117
|
/**
|
|
94
118
|
* ```js
|
|
95
119
|
* await auth0.checkSession();
|
|
@@ -276,4 +300,20 @@ export declare class Auth0Client {
|
|
|
276
300
|
* Check the `EXAMPLES.md` file for a deeper look into this method.
|
|
277
301
|
*/
|
|
278
302
|
createFetcher<TOutput extends CustomFetchMinimalOutput = Response>(config?: FetcherConfig<TOutput>): Fetcher<TOutput>;
|
|
303
|
+
/**
|
|
304
|
+
* Initiates a redirect to connect the user's account with a specified connection.
|
|
305
|
+
* This method generates PKCE parameters, creates a transaction, and redirects to the /connect endpoint.
|
|
306
|
+
*
|
|
307
|
+
* @template TAppState - The application state to persist through the transaction.
|
|
308
|
+
* @param {RedirectConnectAccountOptions<TAppState>} options - Options for the connect account redirect flow.
|
|
309
|
+
* @param {string} options.connection - The name of the connection to link (e.g. 'google-oauth2').
|
|
310
|
+
* @param {AuthorizationParams} [options.authorization_params] - Additional authorization parameters for the request to the upstream IdP.
|
|
311
|
+
* @param {string} [options.redirectUri] - The URI to redirect back to after connecting the account.
|
|
312
|
+
* @param {TAppState} [options.appState] - Application state to persist through the transaction.
|
|
313
|
+
* @param {(url: string) => Promise<void>} [options.openUrl] - Custom function to open the URL.
|
|
314
|
+
*
|
|
315
|
+
* @returns {Promise<void>} Resolves when the redirect is initiated.
|
|
316
|
+
* @throws {MyAccountApiError} If the connect request to the My Account API fails.
|
|
317
|
+
*/
|
|
318
|
+
connectAccountWithRedirect<TAppState = any>(options: RedirectConnectAccountOptions<TAppState>): Promise<void>;
|
|
279
319
|
}
|
|
@@ -32,3 +32,35 @@ export declare const getAuthorizeParams: (clientOptions: Auth0ClientOptions & {
|
|
|
32
32
|
* Function used to provide support for the deprecated onRedirect through openUrl.
|
|
33
33
|
*/
|
|
34
34
|
export declare const patchOpenUrlWithOnRedirect: <T extends Pick<LogoutOptions, "openUrl" | "onRedirect">>(options: T) => T;
|
|
35
|
+
/**
|
|
36
|
+
* @ignore
|
|
37
|
+
*
|
|
38
|
+
* Checks if all scopes are included inside other array of scopes
|
|
39
|
+
*/
|
|
40
|
+
export declare const allScopesAreIncluded: (scopeToInclude?: string, scopes?: string) => boolean;
|
|
41
|
+
/**
|
|
42
|
+
* @ignore
|
|
43
|
+
*
|
|
44
|
+
* For backward compatibility we are going to check if we are going to downscope while doing a refresh request
|
|
45
|
+
* while MRRT is allowed. If the audience is the same for the refresh_token we are going to use and it has
|
|
46
|
+
* lower scopes than the ones originally in the token, we are going to return the scopes that were stored
|
|
47
|
+
* with the refresh_token in the tokenset.
|
|
48
|
+
* @param useMrrt Setting that the user can activate to use MRRT in their requests
|
|
49
|
+
* @param authorizationParams Contains the audience and scope that the user requested to obtain a token
|
|
50
|
+
* @param cachedAudience Audience stored with the refresh_token wich we are going to use in the request
|
|
51
|
+
* @param cachedScope Scope stored with the refresh_token wich we are going to use in the request
|
|
52
|
+
*/
|
|
53
|
+
export declare const getScopeToRequest: (useMrrt: boolean | undefined, authorizationParams: {
|
|
54
|
+
audience?: string;
|
|
55
|
+
scope: string;
|
|
56
|
+
}, cachedAudience?: string, cachedScope?: string) => string;
|
|
57
|
+
/**
|
|
58
|
+
* @ignore
|
|
59
|
+
*
|
|
60
|
+
* Checks if the refresh request has been done using MRRT
|
|
61
|
+
* @param cachedAudience Audience from the refresh token used to refresh
|
|
62
|
+
* @param cachedScope Scopes from the refresh token used to refresh
|
|
63
|
+
* @param requestAudience Audience sent to the server
|
|
64
|
+
* @param requestScope Scopes sent to the server
|
|
65
|
+
*/
|
|
66
|
+
export declare const isRefreshWithMrrt: (cachedAudience: string | undefined, cachedScope: string | undefined, requestAudience: string | undefined, requestScope: string) => boolean;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { AuthorizationParams } from './global';
|
|
2
|
+
import { Fetcher } from './fetcher';
|
|
3
|
+
interface ConnectRequest {
|
|
4
|
+
/** The name of the connection to link the account with (e.g., 'google-oauth2', 'facebook'). */
|
|
5
|
+
connection: string;
|
|
6
|
+
/** The URI to redirect to after the connection process completes. */
|
|
7
|
+
redirect_uri: string;
|
|
8
|
+
/** An opaque value used to maintain state between the request and callback. */
|
|
9
|
+
state?: string;
|
|
10
|
+
/** A string value used to associate a Client session with an ID Token, and to mitigate replay attacks. */
|
|
11
|
+
nonce?: string;
|
|
12
|
+
/** The PKCE code challenge derived from the code verifier. */
|
|
13
|
+
code_challenge?: string;
|
|
14
|
+
/** The method used to derive the code challenge. Required when code_challenge is provided. */
|
|
15
|
+
code_challenge_method?: 'S256';
|
|
16
|
+
authorization_params?: AuthorizationParams;
|
|
17
|
+
}
|
|
18
|
+
interface ConnectResponse {
|
|
19
|
+
/** The base URI to initiate the account connection flow. */
|
|
20
|
+
connect_uri: string;
|
|
21
|
+
/** The authentication session identifier. */
|
|
22
|
+
auth_session: string;
|
|
23
|
+
/** Parameters to be used with the connect URI. */
|
|
24
|
+
connect_params: {
|
|
25
|
+
/** The ticket identifier to be used with the connection URI. */
|
|
26
|
+
ticket: string;
|
|
27
|
+
};
|
|
28
|
+
/** The number of seconds until the ticket expires. */
|
|
29
|
+
expires_in: number;
|
|
30
|
+
}
|
|
31
|
+
interface CompleteRequest {
|
|
32
|
+
/** The authentication session identifier */
|
|
33
|
+
auth_session: string;
|
|
34
|
+
/** The authorization code returned from the connect flow */
|
|
35
|
+
connect_code: string;
|
|
36
|
+
/** The redirect URI used in the original request */
|
|
37
|
+
redirect_uri: string;
|
|
38
|
+
/** The PKCE code verifier */
|
|
39
|
+
code_verifier?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface CompleteResponse {
|
|
42
|
+
/** The unique identifier of the connected account */
|
|
43
|
+
id: string;
|
|
44
|
+
/** The connection name */
|
|
45
|
+
connection: string;
|
|
46
|
+
/** The access type, always 'offline' */
|
|
47
|
+
access_type: 'offline';
|
|
48
|
+
/** Array of scopes granted */
|
|
49
|
+
scopes?: string[];
|
|
50
|
+
/** ISO date string of when the connected account was created */
|
|
51
|
+
created_at: string;
|
|
52
|
+
/** ISO date string of when the refresh token expires (optional) */
|
|
53
|
+
expires_at?: string;
|
|
54
|
+
}
|
|
55
|
+
export interface ErrorResponse {
|
|
56
|
+
type: string;
|
|
57
|
+
status: number;
|
|
58
|
+
title: string;
|
|
59
|
+
detail: string;
|
|
60
|
+
validation_errors?: {
|
|
61
|
+
detail: string;
|
|
62
|
+
field?: string;
|
|
63
|
+
pointer?: string;
|
|
64
|
+
source?: string;
|
|
65
|
+
}[];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Subset of the MyAccount API that handles the connect accounts flow.
|
|
69
|
+
*/
|
|
70
|
+
export declare class MyAccountApiClient {
|
|
71
|
+
private myAccountFetcher;
|
|
72
|
+
private apiBase;
|
|
73
|
+
constructor(myAccountFetcher: Fetcher<Response>, apiBase: string);
|
|
74
|
+
/**
|
|
75
|
+
* Get a ticket for the connect account flow.
|
|
76
|
+
*/
|
|
77
|
+
connectAccount(params: ConnectRequest): Promise<ConnectResponse>;
|
|
78
|
+
/**
|
|
79
|
+
* Verify the redirect from the connect account flow and complete the connecting of the account.
|
|
80
|
+
*/
|
|
81
|
+
completeAccount(params: CompleteRequest): Promise<CompleteResponse>;
|
|
82
|
+
private _handleResponse;
|
|
83
|
+
}
|
|
84
|
+
export declare class MyAccountApiError extends Error {
|
|
85
|
+
readonly type: string;
|
|
86
|
+
readonly status: number;
|
|
87
|
+
readonly title: string;
|
|
88
|
+
readonly detail: string;
|
|
89
|
+
readonly validation_errors?: ErrorResponse['validation_errors'];
|
|
90
|
+
constructor({ type, status, title, detail, validation_errors }: ErrorResponse);
|
|
91
|
+
}
|
|
92
|
+
export {};
|
package/dist/typings/api.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { TokenEndpointOptions, TokenEndpointResponse } from './global';
|
|
2
|
-
export declare function oauthToken({ baseUrl, timeout, audience, scope, auth0Client, useFormData, dpop, ...options }: TokenEndpointOptions, worker?: Worker): Promise<TokenEndpointResponse>;
|
|
2
|
+
export declare function oauthToken({ baseUrl, timeout, audience, scope, auth0Client, useFormData, useMrrt, dpop, ...options }: TokenEndpointOptions, worker?: Worker): Promise<TokenEndpointResponse>;
|
|
@@ -7,7 +7,8 @@ export declare class CacheManager {
|
|
|
7
7
|
constructor(cache: ICache, keyManifest?: CacheKeyManifest | undefined, nowProvider?: () => number | Promise<number>);
|
|
8
8
|
setIdToken(clientId: string, idToken: string, decodedToken: DecodedToken): Promise<void>;
|
|
9
9
|
getIdToken(cacheKey: CacheKey): Promise<IdTokenEntry | undefined>;
|
|
10
|
-
get(cacheKey: CacheKey, expiryAdjustmentSeconds?: number): Promise<Partial<CacheEntry> | undefined>;
|
|
10
|
+
get(cacheKey: CacheKey, expiryAdjustmentSeconds?: number, useMrrt?: boolean, cacheMode?: string): Promise<Partial<CacheEntry> | undefined>;
|
|
11
|
+
private modifiedCachedEntry;
|
|
11
12
|
set(entry: CacheEntry): Promise<void>;
|
|
12
13
|
clear(clientId?: string): Promise<void>;
|
|
13
14
|
private wrapCacheEntry;
|
|
@@ -31,4 +32,20 @@ export declare class CacheManager {
|
|
|
31
32
|
* @param allKeys A list of existing cache keys
|
|
32
33
|
*/
|
|
33
34
|
private matchExistingCacheKey;
|
|
35
|
+
/**
|
|
36
|
+
* Returns the first entry that contains a refresh_token that satisfies the following conditions
|
|
37
|
+
* The keys inside the cache are in the format {prefix}::{clientId}::{audience}::{scope}.
|
|
38
|
+
* - `prefix` is strict equal to Auth0's internally configured `keyPrefix`
|
|
39
|
+
* - `clientId` is strict equal to the `cacheKey.clientId`
|
|
40
|
+
* @param keyToMatch The provided cache key
|
|
41
|
+
* @param allKeys A list of existing cache keys
|
|
42
|
+
*/
|
|
43
|
+
private getEntryWithRefreshToken;
|
|
44
|
+
/**
|
|
45
|
+
* Updates in the cache all entries that has a match with previous refresh_token with the
|
|
46
|
+
* new refresh_token obtained from the server
|
|
47
|
+
* @param oldRefreshToken Old refresh_token used on refresh
|
|
48
|
+
* @param newRefreshToken New refresh_token obtained from the server after refresh
|
|
49
|
+
*/
|
|
50
|
+
updateEntry(oldRefreshToken: string, newRefreshToken: string): Promise<void>;
|
|
34
51
|
}
|
package/dist/typings/errors.d.ts
CHANGED
|
@@ -19,6 +19,16 @@ export declare class AuthenticationError extends GenericError {
|
|
|
19
19
|
appState: any;
|
|
20
20
|
constructor(error: string, error_description: string, state: string, appState?: any);
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Thrown when handling the redirect callback for the connect flow fails, will be one of Auth0's
|
|
24
|
+
* Authentication API's Standard Error Responses: https://auth0.com/docs/api/authentication?javascript#standard-error-responses
|
|
25
|
+
*/
|
|
26
|
+
export declare class ConnectError extends GenericError {
|
|
27
|
+
connection: string;
|
|
28
|
+
state: string;
|
|
29
|
+
appState: any;
|
|
30
|
+
constructor(error: string, error_description: string, connection: string, state: string, appState?: any);
|
|
31
|
+
}
|
|
22
32
|
/**
|
|
23
33
|
* Thrown when silent auth times out (usually due to a configuration issue) or
|
|
24
34
|
* when network requests to the Auth server timeout.
|
|
@@ -6,7 +6,11 @@ export type CustomFetchMinimalOutput = {
|
|
|
6
6
|
headers: ResponseHeaders;
|
|
7
7
|
};
|
|
8
8
|
export type CustomFetchImpl<TOutput extends CustomFetchMinimalOutput> = (req: Request) => Promise<TOutput>;
|
|
9
|
-
type
|
|
9
|
+
export type AuthParams = {
|
|
10
|
+
scope?: string[];
|
|
11
|
+
audience?: string;
|
|
12
|
+
};
|
|
13
|
+
type AccessTokenFactory = (authParams?: AuthParams) => Promise<string>;
|
|
10
14
|
export type FetcherConfig<TOutput extends CustomFetchMinimalOutput> = {
|
|
11
15
|
getAccessToken?: AccessTokenFactory;
|
|
12
16
|
baseUrl?: string;
|
|
@@ -15,7 +19,7 @@ export type FetcherConfig<TOutput extends CustomFetchMinimalOutput> = {
|
|
|
15
19
|
};
|
|
16
20
|
export type FetcherHooks = {
|
|
17
21
|
isDpopEnabled: () => boolean;
|
|
18
|
-
getAccessToken:
|
|
22
|
+
getAccessToken: AccessTokenFactory;
|
|
19
23
|
getDpopNonce: () => Promise<string | undefined>;
|
|
20
24
|
setDpopNonce: (nonce: string) => Promise<void>;
|
|
21
25
|
generateDpopProof: (params: {
|
|
@@ -34,15 +38,15 @@ export declare class Fetcher<TOutput extends CustomFetchMinimalOutput> {
|
|
|
34
38
|
constructor(config: FetcherConfig<TOutput>, hooks: FetcherHooks);
|
|
35
39
|
protected isAbsoluteUrl(url: string): boolean;
|
|
36
40
|
protected buildUrl(baseUrl: string | undefined, url: string | undefined): string;
|
|
37
|
-
protected getAccessToken(): Promise<string>;
|
|
41
|
+
protected getAccessToken(authParams?: AuthParams): Promise<string>;
|
|
38
42
|
protected buildBaseRequest(info: RequestInfo | URL, init: RequestInit | undefined): Request;
|
|
39
|
-
protected setAuthorizationHeader(request: Request, accessToken: string):
|
|
43
|
+
protected setAuthorizationHeader(request: Request, accessToken: string): void;
|
|
40
44
|
protected setDpopProofHeader(request: Request, accessToken: string): Promise<void>;
|
|
41
|
-
protected prepareRequest(request: Request): Promise<void>;
|
|
45
|
+
protected prepareRequest(request: Request, authParams?: AuthParams): Promise<void>;
|
|
42
46
|
protected getHeader(headers: ResponseHeaders, name: string): string;
|
|
43
47
|
protected hasUseDpopNonceError(response: TOutput): boolean;
|
|
44
48
|
protected handleResponse(response: TOutput, callbacks: FetchWithAuthCallbacks<TOutput>): Promise<TOutput>;
|
|
45
|
-
protected internalFetchWithAuth(info: RequestInfo | URL, init: RequestInit | undefined, callbacks: FetchWithAuthCallbacks<TOutput
|
|
46
|
-
fetchWithAuth(info: RequestInfo | URL, init?: RequestInit): Promise<TOutput>;
|
|
49
|
+
protected internalFetchWithAuth(info: RequestInfo | URL, init: RequestInit | undefined, callbacks: FetchWithAuthCallbacks<TOutput>, authParams?: AuthParams): Promise<TOutput>;
|
|
50
|
+
fetchWithAuth(info: RequestInfo | URL, init?: RequestInit, authParams?: AuthParams): Promise<TOutput>;
|
|
47
51
|
}
|
|
48
52
|
export {};
|
package/dist/typings/global.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ICache } from './cache';
|
|
2
2
|
import type { Dpop } from './dpop/dpop';
|
|
3
|
+
import { CompleteResponse } from './MyAccountApiClient';
|
|
3
4
|
export interface AuthorizationParams {
|
|
4
5
|
/**
|
|
5
6
|
* - `'page'`: displays the UI with a full page view
|
|
@@ -243,6 +244,10 @@ export interface Auth0ClientOptions extends BaseLoginOptions {
|
|
|
243
244
|
* **Note**: The worker is only used when `useRefreshTokens: true`, `cacheLocation: 'memory'`, and the `cache` is not custom.
|
|
244
245
|
*/
|
|
245
246
|
workerUrl?: string;
|
|
247
|
+
/**
|
|
248
|
+
* If `true`, the SDK will allow the refreshing of tokens using MRRT
|
|
249
|
+
*/
|
|
250
|
+
useMrrt?: boolean;
|
|
246
251
|
/**
|
|
247
252
|
* If `true`, DPoP (OAuth 2.0 Demonstrating Proof of Possession, RFC9449)
|
|
248
253
|
* will be used to cryptographically bind tokens to this specific browser
|
|
@@ -311,11 +316,24 @@ export interface RedirectLoginOptions<TAppState = any> extends BaseLoginOptions
|
|
|
311
316
|
*/
|
|
312
317
|
openUrl?: (url: string) => Promise<void> | void;
|
|
313
318
|
}
|
|
319
|
+
/**
|
|
320
|
+
* The types of responses expected from the authorization server.
|
|
321
|
+
* - `code`: used for the standard login flow.
|
|
322
|
+
* - `connect_code`: used for the connect account flow.
|
|
323
|
+
*/
|
|
324
|
+
export declare enum ResponseType {
|
|
325
|
+
Code = "code",
|
|
326
|
+
ConnectCode = "connect_code"
|
|
327
|
+
}
|
|
314
328
|
export interface RedirectLoginResult<TAppState = any> {
|
|
315
329
|
/**
|
|
316
330
|
* State stored when the redirect request was made
|
|
317
331
|
*/
|
|
318
332
|
appState?: TAppState;
|
|
333
|
+
/**
|
|
334
|
+
* The type of response, for login it will be `code`
|
|
335
|
+
*/
|
|
336
|
+
response_type: ResponseType.Code;
|
|
319
337
|
}
|
|
320
338
|
export interface PopupLoginOptions extends BaseLoginOptions {
|
|
321
339
|
}
|
|
@@ -465,12 +483,91 @@ export interface LogoutOptions extends LogoutUrlOptions {
|
|
|
465
483
|
*/
|
|
466
484
|
openUrl?: false | ((url: string) => Promise<void> | void);
|
|
467
485
|
}
|
|
486
|
+
export interface RedirectConnectAccountOptions<TAppState = any> {
|
|
487
|
+
/**
|
|
488
|
+
* The name of the connection to link (e.g. 'google-oauth2').
|
|
489
|
+
*/
|
|
490
|
+
connection: string;
|
|
491
|
+
/**
|
|
492
|
+
* Additional authorization parameters for the request.
|
|
493
|
+
*
|
|
494
|
+
* @example
|
|
495
|
+
* await auth0.connectAccountWithRedirect({
|
|
496
|
+
* connection: 'google-oauth2',
|
|
497
|
+
* authorization_params: {
|
|
498
|
+
* scope: 'https://www.googleapis.com/auth/calendar'
|
|
499
|
+
* access_type: 'offline'
|
|
500
|
+
* }
|
|
501
|
+
* });
|
|
502
|
+
*
|
|
503
|
+
* @example
|
|
504
|
+
* await auth0.connectAccountWithRedirect({
|
|
505
|
+
* connection: 'github',
|
|
506
|
+
* authorization_params: {
|
|
507
|
+
* scope: 'repo user',
|
|
508
|
+
* audience: 'https://api.github.com'
|
|
509
|
+
* }
|
|
510
|
+
* });
|
|
511
|
+
*/
|
|
512
|
+
authorization_params?: AuthorizationParams;
|
|
513
|
+
/**
|
|
514
|
+
* The URI to redirect back to after connecting the account.
|
|
515
|
+
*/
|
|
516
|
+
redirectUri?: string;
|
|
517
|
+
/**
|
|
518
|
+
* Optional application state to persist through the transaction.
|
|
519
|
+
*
|
|
520
|
+
* @example
|
|
521
|
+
* await auth0.connectAccountWithRedirect({
|
|
522
|
+
* connection: 'google-oauth2',
|
|
523
|
+
* appState: { returnTo: '/settings' }
|
|
524
|
+
* });
|
|
525
|
+
*/
|
|
526
|
+
appState?: TAppState;
|
|
527
|
+
/**
|
|
528
|
+
* Optional function to handle the redirect URL.
|
|
529
|
+
*
|
|
530
|
+
* @example
|
|
531
|
+
* await auth0.connectAccountWithRedirect({
|
|
532
|
+
* connection: 'google-oauth2',
|
|
533
|
+
* openUrl: async (url) => { myBrowserApi.open(url); }
|
|
534
|
+
* });
|
|
535
|
+
*/
|
|
536
|
+
openUrl?: (url: string) => Promise<void>;
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* The result returned after a successful account connection redirect.
|
|
540
|
+
*
|
|
541
|
+
* Combines the redirect login result (including any persisted app state)
|
|
542
|
+
* with the complete response from the My Account API.
|
|
543
|
+
*
|
|
544
|
+
* @template TAppState - The type of application state persisted through the transaction.
|
|
545
|
+
* @example
|
|
546
|
+
* const result = await auth0.connectAccountWithRedirect(options);
|
|
547
|
+
* console.log(result.appState); // Access persisted app state
|
|
548
|
+
* console.log(result.connection); // The connection of the account you connected to.
|
|
549
|
+
* console.log(result.response_type === 'connect_code'); // The response type will be 'connect_code'
|
|
550
|
+
*/
|
|
551
|
+
export type ConnectAccountRedirectResult<TAppState = any> = CompleteResponse & {
|
|
552
|
+
/**
|
|
553
|
+
* State stored when the redirect request was made
|
|
554
|
+
*/
|
|
555
|
+
appState?: TAppState;
|
|
556
|
+
/**
|
|
557
|
+
* The type of response, for connect account it will be `connect_code`
|
|
558
|
+
*/
|
|
559
|
+
response_type: ResponseType.ConnectCode;
|
|
560
|
+
};
|
|
468
561
|
/**
|
|
469
562
|
* @ignore
|
|
470
563
|
*/
|
|
471
564
|
export interface AuthenticationResult {
|
|
472
565
|
state: string;
|
|
473
566
|
code?: string;
|
|
567
|
+
/**
|
|
568
|
+
* This is for the redirect from the connect account flow.
|
|
569
|
+
*/
|
|
570
|
+
connect_code?: string;
|
|
474
571
|
error?: string;
|
|
475
572
|
error_description?: string;
|
|
476
573
|
}
|
package/dist/typings/http.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FetchOptions } from './global';
|
|
2
2
|
import { Dpop } from './dpop/dpop';
|
|
3
3
|
export declare const createAbortController: () => AbortController;
|
|
4
|
-
export declare const switchFetch: (fetchUrl: string, audience: string, scope: string, fetchOptions: FetchOptions, worker?: Worker, useFormData?: boolean, timeout?: number) => Promise<any>;
|
|
5
|
-
export declare function getJSON<T>(url: string, timeout: number | undefined, audience: string, scope: string, options: FetchOptions, worker?: Worker, useFormData?: boolean, dpop?: Pick<Dpop, 'generateProof' | 'getNonce' | 'setNonce'>, isDpopRetry?: boolean): Promise<T>;
|
|
4
|
+
export declare const switchFetch: (fetchUrl: string, audience: string, scope: string, fetchOptions: FetchOptions, worker?: Worker, useFormData?: boolean, timeout?: number, useMrrt?: boolean) => Promise<any>;
|
|
5
|
+
export declare function getJSON<T>(url: string, timeout: number | undefined, audience: string, scope: string, options: FetchOptions, worker?: Worker, useFormData?: boolean, useMrrt?: boolean, dpop?: Pick<Dpop, 'generateProof' | 'getNonce' | 'setNonce'>, isDpopRetry?: boolean): Promise<T>;
|
package/dist/typings/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export * from './global';
|
|
|
13
13
|
*/
|
|
14
14
|
export declare function createAuth0Client(options: Auth0ClientOptions): Promise<Auth0Client>;
|
|
15
15
|
export { Auth0Client };
|
|
16
|
-
export { GenericError, AuthenticationError, TimeoutError, PopupTimeoutError, PopupCancelledError, MfaRequiredError, MissingRefreshTokenError, UseDpopNonceError } from './errors';
|
|
16
|
+
export { ConnectError, GenericError, AuthenticationError, TimeoutError, PopupTimeoutError, PopupCancelledError, MfaRequiredError, MissingRefreshTokenError, UseDpopNonceError } from './errors';
|
|
17
17
|
export { ICache, LocalStorageCache, InMemoryCache, Cacheable, DecodedToken, CacheEntry, WrappedCacheEntry, KeyManifestEntry, MaybePromise, CacheKey, CacheKeyData } from './cache';
|
|
18
18
|
export { type FetcherConfig } from './fetcher';
|
|
19
|
+
export { MyAccountApiError } from './MyAccountApiClient';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ClientStorage } from './storage';
|
|
2
|
-
interface
|
|
2
|
+
export interface LoginTransaction {
|
|
3
3
|
nonce: string;
|
|
4
4
|
scope: string;
|
|
5
5
|
audience: string;
|
|
@@ -8,6 +8,18 @@ interface Transaction {
|
|
|
8
8
|
redirect_uri?: string;
|
|
9
9
|
organization?: string;
|
|
10
10
|
state?: string;
|
|
11
|
+
response_type: 'code';
|
|
12
|
+
}
|
|
13
|
+
export interface ConnectAccountTransaction {
|
|
14
|
+
appState?: any;
|
|
15
|
+
audience?: string;
|
|
16
|
+
auth_session: string;
|
|
17
|
+
code_verifier: string;
|
|
18
|
+
redirect_uri: string;
|
|
19
|
+
scope?: string;
|
|
20
|
+
state: string;
|
|
21
|
+
connection: string;
|
|
22
|
+
response_type: 'connect_code';
|
|
11
23
|
}
|
|
12
24
|
export declare class TransactionManager {
|
|
13
25
|
private storage;
|
|
@@ -15,8 +27,7 @@ export declare class TransactionManager {
|
|
|
15
27
|
private cookieDomain?;
|
|
16
28
|
private storageKey;
|
|
17
29
|
constructor(storage: ClientStorage, clientId: string, cookieDomain?: string | undefined);
|
|
18
|
-
create(transaction:
|
|
19
|
-
get():
|
|
30
|
+
create<T extends Object = LoginTransaction>(transaction: T): void;
|
|
31
|
+
get<T extends Object = LoginTransaction>(): T | undefined;
|
|
20
32
|
remove(): void;
|
|
21
33
|
}
|
|
22
|
-
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "2.
|
|
1
|
+
declare const _default: "2.6.0";
|
|
2
2
|
export default _default;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "@auth0/auth0-spa-js",
|
|
4
4
|
"description": "Auth0 SDK for Single Page Applications using Authorization Code Grant Flow with PKCE",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "2.
|
|
6
|
+
"version": "2.6.0",
|
|
7
7
|
"main": "dist/lib/auth0-spa-js.cjs.js",
|
|
8
8
|
"types": "dist/typings/index.d.ts",
|
|
9
9
|
"module": "dist/auth0-spa-js.production.esm.js",
|