@versini/auth0-react-thin 2.24.1 → 2.27.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.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  export { default as Auth0Provider, Auth0ProviderOptions, Auth0ProviderWithConfigOptions, Auth0ProviderWithClientOptions, AppState, ConnectedAccount } from './auth0-provider';
2
2
  export { default as useAuth0 } from './use-auth0';
3
3
  export { default as useAuth0Suspense, Auth0SuspenseContextInterface, } from './use-auth0-suspense';
4
+ export { default as useEnterpriseConnect, UseEnterpriseConnect, } from './use-enterprise-connect';
4
5
  export { default as withAuth0, WithAuth0Props } from './with-auth0';
5
6
  export { default as withAuthenticationRequired, WithAuthenticationRequiredOptions, } from './with-authentication-required';
6
7
  export { default as Auth0Context, Auth0ContextInterface, initialContext, LogoutOptions, RedirectLoginOptions, } from './auth0-context';
7
- export { AuthorizationParams, PopupLoginOptions, PopupConfigOptions, GetTokenWithPopupOptions, LogoutUrlOptions, CacheLocation, GetTokenSilentlyOptions, IdToken, User, ICache, InMemoryCache, LocalStorageCache, Cacheable, TimeoutError, MfaRequiredError, PopupCancelledError, PopupTimeoutError, PopupOpenError, AuthenticationError, MissingRefreshTokenError, MissingScopesError, InvalidConfigurationError, GenericError, UseDpopNonceError, RedirectConnectAccountOptions, ConnectAccountRedirectResult, ResponseType, ConnectError, CustomTokenExchangeOptions, TokenEndpointResponse, ActClaim, ClientConfiguration, RefreshTokenMode, MfaError, MfaListAuthenticatorsError, MfaEnrollmentError, MfaChallengeError, MfaVerifyError, MfaEnrollmentFactorsError, PasskeyError, PasskeyRegisterError, PasskeyChallengeError, PasskeyGetTokenError, MyAccountApiError, } from '@auth0/auth0-spa-js';
8
- export type { RevokeRefreshTokenOptions, FetcherConfig, InteractiveErrorHandler, MfaApiClient, Authenticator, MfaFactorType, EnrollParams, EnrollOtpParams, EnrollSmsParams, EnrollVoiceParams, EnrollEmailParams, EnrollPushParams, EnrollmentResponse, ChallengeAuthenticatorParams, ChallengeResponse, VerifyParams, EnrollmentFactor, PasskeyApiClient, PasskeySignupOptions, PasskeyLoginOptions, MyAccountApiClient, AuthenticationMethod, AuthenticationMethodType, Factor, UpdateAuthenticationMethodRequest, EnrollmentChallengeOptions, EnrollmentChallengeResponse, EnrollmentVerifyOptions, } from '@auth0/auth0-spa-js';
8
+ export { AuthorizationParams, PopupLoginOptions, PopupConfigOptions, GetTokenWithPopupOptions, LogoutUrlOptions, CacheLocation, GetTokenSilentlyOptions, IdToken, User, ICache, InMemoryCache, LocalStorageCache, Cacheable, TimeoutError, MfaRequiredError, PopupCancelledError, PopupTimeoutError, PopupOpenError, AuthenticationError, MissingRefreshTokenError, MissingScopesError, InvalidConfigurationError, GenericError, UseDpopNonceError, RedirectConnectAccountOptions, ConnectAccountRedirectResult, ResponseType, ConnectError, CustomTokenExchangeOptions, TokenEndpointResponse, ActClaim, ClientConfiguration, RefreshTokenMode, MfaError, MfaListAuthenticatorsError, MfaEnrollmentError, MfaChallengeError, MfaVerifyError, MfaEnrollmentFactorsError, PasskeyError, PasskeyRegisterError, PasskeyChallengeError, PasskeyGetTokenError, MyAccountApiError, AnonymousSessionError, } from '@auth0/auth0-spa-js';
9
+ export type { RevokeRefreshTokenOptions, FetcherConfig, InteractiveErrorHandler, IsFederatedDomainOptions, MfaApiClient, Authenticator, MfaFactorType, EnrollParams, EnrollOtpParams, EnrollSmsParams, EnrollVoiceParams, EnrollEmailParams, EnrollPushParams, EnrollmentResponse, ChallengeAuthenticatorParams, ChallengeResponse, VerifyParams, EnrollmentFactor, PasskeyApiClient, PasskeySignupOptions, PasskeyLoginOptions, MyAccountApiClient, AuthenticationMethod, AuthenticationMethodType, Factor, UpdateAuthenticationMethodRequest, EnrollmentChallengeOptions, EnrollmentChallengeResponse, EnrollmentVerifyOptions, AnonymousSessionApiClient, AnonymousGetTokenSilentlyOptions, AnonymousSession, AnonymousSessionClaims, AnonymousSessionErrorCode, CreateAnonymousSessionOptions, } from '@auth0/auth0-spa-js';
9
10
  export { OAuthError } from './errors';
10
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,IAAI,aAAa,EACxB,oBAAoB,EACpB,8BAA8B,EAC9B,8BAA8B,EAC9B,QAAQ,EACR,gBAAgB,EACjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EACL,OAAO,IAAI,gBAAgB,EAC3B,6BAA6B,GAC9B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EACL,OAAO,IAAI,0BAA0B,EACrC,iCAAiC,GAClC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,OAAO,IAAI,YAAY,EACvB,qBAAqB,EACrB,cAAc,EACd,aAAa,EACb,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACxB,gBAAgB,EAChB,aAAa,EACb,uBAAuB,EACvB,OAAO,EACP,IAAI,EACJ,MAAM,EACN,aAAa,EACb,iBAAiB,EACjB,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,wBAAwB,EACxB,kBAAkB,EAClB,yBAAyB,EACzB,YAAY,EACZ,iBAAiB,EACjB,6BAA6B,EAC7B,4BAA4B,EAC5B,YAAY,EACZ,YAAY,EACZ,0BAA0B,EAC1B,qBAAqB,EACrB,QAAQ,EACR,mBAAmB,EACnB,gBAAgB,EAEhB,QAAQ,EACR,0BAA0B,EAC1B,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,E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UAAU,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,33 @@
1
+ import { IsFederatedDomainOptions } from '@auth0/auth0-spa-js';
2
+ import { Auth0ContextInterface, RedirectLoginOptions } from './auth0-context';
3
+ /**
4
+ * The shape returned by the `useEnterpriseConnect` hook.
5
+ */
6
+ export interface UseEnterpriseConnect {
7
+ /**
8
+ * Runs WebFinger domain discovery for the given email domain against the
9
+ * Auth0 domain configured on the `Auth0Provider`. Returns `true` only if
10
+ * the domain is managed by Auth0 for enterprise SSO. A routing hint, not a
11
+ * security control: it returns `false` on any failure.
12
+ */
13
+ isFederatedDomain: (emailDomain: string, options?: IsFederatedDomainOptions) => Promise<boolean>;
14
+ /**
15
+ * Starts the enterprise SSO redirect, passing the email as `login_hint`
16
+ * so Home Realm Discovery can resolve the connection and organization. Any
17
+ * `authorizationParams` supplied by the caller are preserved.
18
+ */
19
+ loginWithSSO: (email: string, options?: RedirectLoginOptions) => Promise<void>;
20
+ }
21
+ /**
22
+ * ```js
23
+ * const { isFederatedDomain, loginWithSSO } = useEnterpriseConnect();
24
+ * ```
25
+ *
26
+ * Convenience hook for the Enterprise Connect flow. `isFederatedDomain` reads
27
+ * the Auth0 domain from the `Auth0Provider` configuration, so callers pass
28
+ * only the email domain. `loginWithSSO` is sugar over `loginWithRedirect`
29
+ * that sets `login_hint` to the provided email.
30
+ */
31
+ declare const useEnterpriseConnect: (context?: import("react").Context<Auth0ContextInterface<import("@auth0/auth0-spa-js").User>>) => UseEnterpriseConnect;
32
+ export default useEnterpriseConnect;
33
+ //# sourceMappingURL=use-enterprise-connect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-enterprise-connect.d.ts","sourceRoot":"","sources":["../src/use-enterprise-connect.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,wBAAwB,EACzB,MAAM,qBAAqB,CAAC;AAC7B,OAAqB,EACnB,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,iBAAiB,CAAC;AAEzB;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;;OAKG;IACH,iBAAiB,EAAE,CACjB,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,wBAAwB,KAC/B,OAAO,CAAC,OAAO,CAAC,CAAC;IACtB;;;;OAIG;IACH,YAAY,EAAE,CACZ,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,oBAAoB,KAC3B,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB;AAED;;;;;;;;;GASG;AACH,QAAA,MAAM,oBAAoB,GACxB,4FAAsB,KACrB,oBAyBF,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "author": "Auth0",
3
3
  "name": "@versini/auth0-react-thin",
4
- "version": "2.24.1",
5
- "description": "Unofficial slim fork of @auth0/auth0-react@2.24.1 — bundle-size build, not affiliated with Auth0/Okta. See @versini/auth0-thin.",
4
+ "version": "2.27.0",
5
+ "description": "Unofficial slim fork of @auth0/auth0-react@2.27.0 — bundle-size build, not affiliated with Auth0/Okta. See @versini/auth0-thin.",
6
6
  "keywords": [
7
7
  "auth0",
8
8
  "fork",
@@ -32,9 +32,9 @@
32
32
  "react-dom": "^16.11.0 || ^17 || ^18 || ~19.0.1 || ~19.1.2 || ^19.2.1"
33
33
  },
34
34
  "dependencies": {
35
- "@auth0/auth0-spa-js": "^2.24.1"
35
+ "@auth0/auth0-spa-js": "^2.27.0"
36
36
  },
37
- "forkedFrom": "@auth0/auth0-react@2.24.1",
37
+ "forkedFrom": "@auth0/auth0-react@2.27.0",
38
38
  "publishConfig": {
39
39
  "access": "public"
40
40
  }
@@ -1,5 +1,4 @@
1
1
  import {
2
- GetTokenSilentlyOptions,
3
2
  GetTokenWithPopupOptions,
4
3
  IdToken,
5
4
  LogoutOptions as SPALogoutOptions,
@@ -7,7 +6,6 @@ import {
7
6
  PopupConfigOptions,
8
7
  RedirectLoginResult,
9
8
  User,
10
- GetTokenSilentlyVerboseResponse,
11
9
  RedirectLoginOptions as SPARedirectLoginOptions,
12
10
  type Auth0Client,
13
11
  RedirectConnectAccountOptions,
@@ -17,7 +15,8 @@ import {
17
15
  type RevokeRefreshTokenOptions,
18
16
  type MfaApiClient,
19
17
  type PasskeyApiClient,
20
- type MyAccountApiClient
18
+ type MyAccountApiClient,
19
+ type AnonymousSessionApiClient
21
20
  } from '@auth0/auth0-spa-js';
22
21
  import { createContext } from 'react';
23
22
  import { AuthState, initialAuthState } from './auth-state';
@@ -47,7 +46,7 @@ export interface Auth0ContextInterface<TUser extends User = User>
47
46
  *
48
47
  * If refresh tokens are used, the token endpoint is called directly with the
49
48
  * 'refresh_token' grant. If no refresh token is available to make this call,
50
- * the SDK will only fall back to using an iframe to the '/authorize' URL if
49
+ * the SDK will only fall back to using an iframe to the '/authorize' URL if
51
50
  * the `useRefreshTokensFallback` setting has been set to `true`. By default this
52
51
  * setting is `false`.
53
52
  *
@@ -60,15 +59,7 @@ export interface Auth0ContextInterface<TUser extends User = User>
60
59
  * Note that in all cases, falling back to an iframe requires access to
61
60
  * the `auth0` cookie.
62
61
  */
63
- getAccessTokenSilently: {
64
- (
65
- options: GetTokenSilentlyOptions & { detailedResponse: true }
66
- ): Promise<GetTokenSilentlyVerboseResponse>;
67
- (options?: GetTokenSilentlyOptions): Promise<string>;
68
- (options: GetTokenSilentlyOptions): Promise<
69
- GetTokenSilentlyVerboseResponse | string
70
- >;
71
- };
62
+ getAccessTokenSilently: Auth0Client['getTokenSilently'];
72
63
 
73
64
  /**
74
65
  * ```js
@@ -475,6 +466,21 @@ export interface Auth0ContextInterface<TUser extends User = User>
475
466
  */
476
467
  myAccount: MyAccountApiClient;
477
468
 
469
+ /**
470
+ * ```js
471
+ * const { anonymous } = useAuth0();
472
+ * const { accessToken } = await anonymous.getTokenSilently({ audience: 'https://api.example.com' });
473
+ * ```
474
+ *
475
+ * Anonymous session client for pre-authentication identity management.
476
+ *
477
+ * - `createSession(options?)` - Create a new anonymous session
478
+ * - `getTokenSilently(options?)` - Get or renew an anonymous access token
479
+ * - `logout()` - End the anonymous session and clear stored tokens
480
+ * - `getClaims()` - Always returns `null` in EA
481
+ */
482
+ anonymous: AnonymousSessionApiClient;
483
+
478
484
  /**
479
485
  * Internal. A promise that resolves when Auth0 initialization completes and
480
486
  * rejects with the initialization error if it fails. Consumed by
@@ -537,6 +543,13 @@ export const initialContext = {
537
543
  enrollmentChallenge: stub,
538
544
  enrollmentVerify: stub,
539
545
  } as unknown as MyAccountApiClient,
546
+ anonymous: {
547
+ createSession: stub,
548
+ getTokenSilently: stub,
549
+ logout: stub,
550
+ hasSession: stub,
551
+ getClaims: stub,
552
+ } as unknown as AnonymousSessionApiClient,
540
553
  };
541
554
 
542
555
  /**
@@ -490,6 +490,7 @@ const Auth0Provider = <TUser extends User = User>(opts: Auth0ProviderOptions<TUs
490
490
 
491
491
  const mfa = useMemo(() => client.mfa, [client]);
492
492
  const myAccount = useMemo(() => client.myAccount, [client]);
493
+ const anonymous = useMemo(() => client.anonymous, [client]);
493
494
 
494
495
  const passkeySignup = useCallback(
495
496
  async (options: PasskeySignupOptions): Promise<TokenEndpointResponse> => {
@@ -555,6 +556,7 @@ const Auth0Provider = <TUser extends User = User>(opts: Auth0ProviderOptions<TUs
555
556
  mfa,
556
557
  passkey,
557
558
  myAccount,
559
+ anonymous,
558
560
  _initPromise: initDeferred.promise,
559
561
  };
560
562
  }, [
@@ -579,6 +581,7 @@ const Auth0Provider = <TUser extends User = User>(opts: Auth0ProviderOptions<TUs
579
581
  mfa,
580
582
  passkey,
581
583
  myAccount,
584
+ anonymous,
582
585
  initDeferred,
583
586
  ]);
584
587
 
package/src/index.tsx CHANGED
@@ -11,6 +11,10 @@ export {
11
11
  default as useAuth0Suspense,
12
12
  Auth0SuspenseContextInterface,
13
13
  } from './use-auth0-suspense';
14
+ export {
15
+ default as useEnterpriseConnect,
16
+ UseEnterpriseConnect,
17
+ } from './use-enterprise-connect';
14
18
  export { default as withAuth0, WithAuth0Props } from './with-auth0';
15
19
  export {
16
20
  default as withAuthenticationRequired,
@@ -71,11 +75,14 @@ export {
71
75
  PasskeyGetTokenError,
72
76
  // MyAccount Errors
73
77
  MyAccountApiError,
78
+ // Anonymous Session Errors
79
+ AnonymousSessionError,
74
80
  } from '@auth0/auth0-spa-js';
75
81
  export type {
76
82
  RevokeRefreshTokenOptions,
77
83
  FetcherConfig,
78
84
  InteractiveErrorHandler,
85
+ IsFederatedDomainOptions,
79
86
  // MFA Types
80
87
  MfaApiClient,
81
88
  Authenticator,
@@ -104,5 +111,12 @@ export type {
104
111
  EnrollmentChallengeOptions,
105
112
  EnrollmentChallengeResponse,
106
113
  EnrollmentVerifyOptions,
114
+ // Anonymous Session Types
115
+ AnonymousSessionApiClient,
116
+ AnonymousGetTokenSilentlyOptions,
117
+ AnonymousSession,
118
+ AnonymousSessionClaims,
119
+ AnonymousSessionErrorCode,
120
+ CreateAnonymousSessionOptions,
107
121
  } from '@auth0/auth0-spa-js';
108
122
  export { OAuthError } from './errors';
@@ -0,0 +1,75 @@
1
+ import { useCallback, useContext } from 'react';
2
+ import {
3
+ isFederatedDomain as spaIsFederatedDomain,
4
+ IsFederatedDomainOptions,
5
+ } from '@auth0/auth0-spa-js';
6
+ import Auth0Context, {
7
+ Auth0ContextInterface,
8
+ RedirectLoginOptions,
9
+ } from './auth0-context';
10
+
11
+ /**
12
+ * The shape returned by the `useEnterpriseConnect` hook.
13
+ */
14
+ export interface UseEnterpriseConnect {
15
+ /**
16
+ * Runs WebFinger domain discovery for the given email domain against the
17
+ * Auth0 domain configured on the `Auth0Provider`. Returns `true` only if
18
+ * the domain is managed by Auth0 for enterprise SSO. A routing hint, not a
19
+ * security control: it returns `false` on any failure.
20
+ */
21
+ isFederatedDomain: (
22
+ emailDomain: string,
23
+ options?: IsFederatedDomainOptions
24
+ ) => Promise<boolean>;
25
+ /**
26
+ * Starts the enterprise SSO redirect, passing the email as `login_hint`
27
+ * so Home Realm Discovery can resolve the connection and organization. Any
28
+ * `authorizationParams` supplied by the caller are preserved.
29
+ */
30
+ loginWithSSO: (
31
+ email: string,
32
+ options?: RedirectLoginOptions
33
+ ) => Promise<void>;
34
+ }
35
+
36
+ /**
37
+ * ```js
38
+ * const { isFederatedDomain, loginWithSSO } = useEnterpriseConnect();
39
+ * ```
40
+ *
41
+ * Convenience hook for the Enterprise Connect flow. `isFederatedDomain` reads
42
+ * the Auth0 domain from the `Auth0Provider` configuration, so callers pass
43
+ * only the email domain. `loginWithSSO` is sugar over `loginWithRedirect`
44
+ * that sets `login_hint` to the provided email.
45
+ */
46
+ const useEnterpriseConnect = (
47
+ context = Auth0Context
48
+ ): UseEnterpriseConnect => {
49
+ const { getConfiguration, loginWithRedirect } = useContext(
50
+ context
51
+ ) as Auth0ContextInterface;
52
+
53
+ const isFederatedDomain = useCallback(
54
+ // domain is read at call time, not when the callback is memoized
55
+ (emailDomain: string, options?: IsFederatedDomainOptions) =>
56
+ spaIsFederatedDomain(getConfiguration().domain, emailDomain, options),
57
+ [getConfiguration]
58
+ );
59
+
60
+ const loginWithSSO = useCallback(
61
+ (email: string, options?: RedirectLoginOptions) =>
62
+ loginWithRedirect({
63
+ ...options,
64
+ authorizationParams: {
65
+ ...options?.authorizationParams,
66
+ login_hint: email,
67
+ },
68
+ }),
69
+ [loginWithRedirect]
70
+ );
71
+
72
+ return { isFederatedDomain, loginWithSSO };
73
+ };
74
+
75
+ export default useEnterpriseConnect;