From bd693e2a053b9f0299338e3c4468056f70ccf927 Mon Sep 17 00:00:00 2001 From: Gyanesh Gouraw Date: Tue, 27 Jan 2026 10:12:20 +0530 Subject: [PATCH 1/2] feat: add getConfiguration method to Auth0Client and updated documentation --- EXAMPLES.md | 29 ++++++++++++++++++++++++++++- __mocks__/@auth0/auth0-spa-js.tsx | 2 ++ __tests__/auth-provider.test.tsx | 24 ++++++++++++++++++++++++ src/auth0-context.tsx | 14 +++++++++++++- src/auth0-provider.tsx | 7 +++++++ src/index.tsx | 3 ++- 6 files changed, 76 insertions(+), 3 deletions(-) diff --git a/EXAMPLES.md b/EXAMPLES.md index fcefdc28..fe7764c8 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -11,6 +11,7 @@ - [Device-bound tokens with DPoP](#device-bound-tokens-with-dpop) - [Using Multi Resource Refresh Tokens](#using-multi-resource-refresh-tokens) - [Connect Accounts for using Token Vault](#connect-accounts-for-using-token-vault) +- [Access SDK Configuration](#access-sdk-configuration) ## Use with a Class Component @@ -737,4 +738,30 @@ When the redirect completes, the user will be returned to the application and th ``` -You can now [call the API](#calling-an-api) with your access token and the API can use [Access Token Exchange with Token Vault](https://auth0.com/docs/secure/tokens/token-vault/access-token-exchange-with-token-vault) to get tokens from the Token Vault to access third party APIs on behalf of the user. \ No newline at end of file +You can now [call the API](#calling-an-api) with your access token and the API can use [Access Token Exchange with Token Vault](https://auth0.com/docs/secure/tokens/token-vault/access-token-exchange-with-token-vault) to get tokens from the Token Vault to access third party APIs on behalf of the user. + +## Access SDK Configuration + +Retrieve the Auth0 domain and client ID that were used to configure the SDK: + +```jsx +import React from 'react'; +import { useAuth0 } from '@auth0/auth0-react'; + +const ConfigInfo = () => { + const { getConfiguration } = useAuth0(); + + const config = getConfiguration(); + + return ( +
+

Domain: {config.domain}

+

Client ID: {config.clientId}

+
+ ); +}; + +export default ConfigInfo; +``` + +This is useful for debugging, logging, or building custom Auth0-related URLs without duplicating configuration values. \ No newline at end of file diff --git a/__mocks__/@auth0/auth0-spa-js.tsx b/__mocks__/@auth0/auth0-spa-js.tsx index 4792c6ca..9012575e 100644 --- a/__mocks__/@auth0/auth0-spa-js.tsx +++ b/__mocks__/@auth0/auth0-spa-js.tsx @@ -18,6 +18,7 @@ const getDpopNonce = jest.fn(); const setDpopNonce = jest.fn(); const generateDpopProof = jest.fn(); const createFetcher = jest.fn(); +const getConfiguration = jest.fn(); export const Auth0Client = jest.fn(() => { return { @@ -39,6 +40,7 @@ export const Auth0Client = jest.fn(() => { setDpopNonce, generateDpopProof, createFetcher, + getConfiguration, }; }); diff --git a/__tests__/auth-provider.test.tsx b/__tests__/auth-provider.test.tsx index 2a3685da..0c958f4e 100644 --- a/__tests__/auth-provider.test.tsx +++ b/__tests__/auth-provider.test.tsx @@ -1257,4 +1257,28 @@ describe('Auth0Provider', () => { expect(screen.queryByText('__custom_user__')).toBeInTheDocument(); expect(screen.queryByText('__main_user__')).not.toBeInTheDocument(); }); + + describe('getConfiguration', () => { + it('should return configuration from Auth0Client', async () => { + clientMock.getConfiguration.mockReturnValue({ + domain: 'test.auth0.com', + clientId: 'test-client-id' + }); + + const wrapper = createWrapper(); + const { result } = renderHook(() => useContext(Auth0Context), { wrapper }); + + await waitFor(() => { + expect(result.current.isLoading).toBe(false); + }); + + const config = result.current.getConfiguration(); + + expect(clientMock.getConfiguration).toHaveBeenCalled(); + expect(config).toEqual({ + domain: 'test.auth0.com', + clientId: 'test-client-id' + }); + }); + }); }); diff --git a/src/auth0-context.tsx b/src/auth0-context.tsx index ba3407cc..146ec21f 100644 --- a/src/auth0-context.tsx +++ b/src/auth0-context.tsx @@ -237,10 +237,21 @@ export interface Auth0ContextInterface * This is a drop-in replacement for the Fetch API's `fetch()` method, but will * handle certain authentication logic for you, like building the proper auth * headers or managing DPoP nonces and retries automatically. - * + * * Check the `EXAMPLES.md` file for a deeper look into this method. */ createFetcher: Auth0Client['createFetcher']; + + /** + * ```js + * const config = getConfiguration(); + * // { domain: 'tenant.auth0.com', clientId: 'abc123' } + * ``` + * + * Returns a readonly copy of the initialization configuration + * containing the domain and clientId. + */ + getConfiguration: Auth0Client['getConfiguration']; } /** @@ -270,6 +281,7 @@ export const initialContext = { setDpopNonce: stub, generateDpopProof: stub, createFetcher: stub, + getConfiguration: stub, }; /** diff --git a/src/auth0-provider.tsx b/src/auth0-provider.tsx index 54eb5451..2027468c 100644 --- a/src/auth0-provider.tsx +++ b/src/auth0-provider.tsx @@ -341,6 +341,11 @@ const Auth0Provider = (opts: Auth0ProviderOptions( + () => client.getConfiguration(), + [client] + ); + const contextValue = useMemo>(() => { return { ...state, @@ -357,6 +362,7 @@ const Auth0Provider = (opts: Auth0ProviderOptions(opts: Auth0ProviderOptions{children}; diff --git a/src/index.tsx b/src/index.tsx index 5d0bb137..8a774540 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -45,6 +45,7 @@ export { ResponseType, ConnectError, CustomTokenExchangeOptions, - TokenEndpointResponse + TokenEndpointResponse, + ClientConfiguration, } from '@auth0/auth0-spa-js'; export { OAuthError } from './errors'; From a6dfbad277e3aa6b2b2d5d55a2a2788217aabe25 Mon Sep 17 00:00:00 2001 From: Gyanesh Gouraw Date: Tue, 27 Jan 2026 14:25:32 +0530 Subject: [PATCH 2/2] feat: update @auth0/auth0-spa-js to version 2.12.0 and add new dependencies --- package-lock.json | 55 ++++++++++++++++++++++++++++++++++++++++++----- package.json | 2 +- 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5dcfcf83..8b77bea5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "2.11.0", "license": "MIT", "dependencies": { - "@auth0/auth0-spa-js": "^2.11.0" + "@auth0/auth0-spa-js": "^2.12.0" }, "devDependencies": { "@rollup/plugin-node-resolve": "^15.0.1", @@ -73,12 +73,29 @@ "node": ">=6.0.0" } }, + "node_modules/@auth0/auth0-auth-js": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@auth0/auth0-auth-js/-/auth0-auth-js-1.4.0.tgz", + "integrity": "sha512-ShA7KT4KvcBEtxsXZTcrmoNxai5q1JXhB2aEBFnZD1L6LNLzzmiUWiFTtGMsaaITCylr8TJ/onEQk6XZmUHXbg==", + "dependencies": { + "jose": "^6.0.8", + "openid-client": "^6.8.0" + } + }, + "node_modules/@auth0/auth0-auth-js/node_modules/jose": { + "version": "6.1.3", + "resolved": "https://registry.npmjs.org/jose/-/jose-6.1.3.tgz", + "integrity": "sha512-0TpaTfihd4QMNwrz/ob2Bp7X04yuxJkjRGi4aKmOqwhov54i6u79oCv7T+C7lo70MKH6BesI3vscD1yb/yzKXQ==", + "funding": { + "url": "https://github.com/sponsors/panva" + } + }, "node_modules/@auth0/auth0-spa-js": { - "version": "2.11.3", - "resolved": "https://registry.npmjs.org/@auth0/auth0-spa-js/-/auth0-spa-js-2.11.3.tgz", - "integrity": "sha512-gdivWytvbatuJ2MVWw2VouqV+dT975yJQXVwdap9d8Sa8KHsybjKoc5TbMqrECwZbXU+nCRIaaBRhL0aiKYA2A==", - "license": "MIT", + "version": "2.12.0", + "resolved": "https://registry.npmjs.org/@auth0/auth0-spa-js/-/auth0-spa-js-2.12.0.tgz", + "integrity": "sha512-Hwn46rz1fqX2Wi2ddhqgE6rymDjZdFYIUL1PDMANLMtvYmeWjBovxcrN7QakeQ7wvmIfDNMqVc/bcByjJoUoBQ==", "dependencies": { + "@auth0/auth0-auth-js": "^1.4.0", "browser-tabs-lock": "^1.2.15", "dpop": "^2.1.1", "es-cookie": "~1.3.2" @@ -9049,6 +9066,14 @@ "dev": true, "license": "MIT" }, + "node_modules/oauth4webapi": { + "version": "3.8.3", + "resolved": "https://registry.npmjs.org/oauth4webapi/-/oauth4webapi-3.8.3.tgz", + "integrity": "sha512-pQ5BsX3QRTgnt5HxgHwgunIRaDXBdkT23tf8dfzmtTIL2LTpdmxgbpbBm0VgFWAIDlezQvQCTgnVIUmHupXHxw==", + "funding": { + "url": "https://github.com/sponsors/panva" + } + }, "node_modules/object-assign": { "version": "4.1.1", "dev": true, @@ -9226,6 +9251,26 @@ "opener": "bin/opener-bin.js" } }, + "node_modules/openid-client": { + "version": "6.8.1", + "resolved": "https://registry.npmjs.org/openid-client/-/openid-client-6.8.1.tgz", + "integrity": "sha512-VoYT6enBo6Vj2j3Q5Ec0AezS+9YGzQo1f5Xc42lreMGlfP4ljiXPKVDvCADh+XHCV/bqPu/wWSiCVXbJKvrODw==", + "dependencies": { + "jose": "^6.1.0", + "oauth4webapi": "^3.8.2" + }, + "funding": { + "url": "https://github.com/sponsors/panva" + } + }, + "node_modules/openid-client/node_modules/jose": { + "version": "6.1.3", + "resolved": "https://registry.npmjs.org/jose/-/jose-6.1.3.tgz", + "integrity": "sha512-0TpaTfihd4QMNwrz/ob2Bp7X04yuxJkjRGi4aKmOqwhov54i6u79oCv7T+C7lo70MKH6BesI3vscD1yb/yzKXQ==", + "funding": { + "url": "https://github.com/sponsors/panva" + } + }, "node_modules/optionator": { "version": "0.9.4", "dev": true, diff --git a/package.json b/package.json index 26780b63..26e23d58 100644 --- a/package.json +++ b/package.json @@ -95,6 +95,6 @@ "react-dom": "^16.11.0 || ^17 || ^18 || ~19.0.1 || ~19.1.2 || ^19.2.1" }, "dependencies": { - "@auth0/auth0-spa-js": "^2.11.0" + "@auth0/auth0-spa-js": "^2.12.0" } }