Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -737,4 +738,30 @@ When the redirect completes, the user will be returned to the application and th
</Auth0Provider>
```

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.
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 (
<div>
<p>Domain: {config.domain}</p>
<p>Client ID: {config.clientId}</p>
</div>
);
};

export default ConfigInfo;
```

This is useful for debugging, logging, or building custom Auth0-related URLs without duplicating configuration values.
2 changes: 2 additions & 0 deletions __mocks__/@auth0/auth0-spa-js.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -39,6 +40,7 @@ export const Auth0Client = jest.fn(() => {
setDpopNonce,
generateDpopProof,
createFetcher,
getConfiguration,
};
});

Expand Down
24 changes: 24 additions & 0 deletions __tests__/auth-provider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
});
});
});
});
55 changes: 50 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
14 changes: 13 additions & 1 deletion src/auth0-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,21 @@ export interface Auth0ContextInterface<TUser extends User = User>
* 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'];
}

/**
Expand Down Expand Up @@ -270,6 +281,7 @@ export const initialContext = {
setDpopNonce: stub,
generateDpopProof: stub,
createFetcher: stub,
getConfiguration: stub,
};

/**
Expand Down
7 changes: 7 additions & 0 deletions src/auth0-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ const Auth0Provider = <TUser extends User = User>(opts: Auth0ProviderOptions<TUs
[client]
);

const getConfiguration = useCallback<Auth0Client['getConfiguration']>(
() => client.getConfiguration(),
[client]
);

const contextValue = useMemo<Auth0ContextInterface<TUser>>(() => {
return {
...state,
Expand All @@ -357,6 +362,7 @@ const Auth0Provider = <TUser extends User = User>(opts: Auth0ProviderOptions<TUs
setDpopNonce,
generateDpopProof,
createFetcher,
getConfiguration,
};
}, [
state,
Expand All @@ -373,6 +379,7 @@ const Auth0Provider = <TUser extends User = User>(opts: Auth0ProviderOptions<TUs
setDpopNonce,
generateDpopProof,
createFetcher,
getConfiguration,
]);

return <context.Provider value={contextValue}>{children}</context.Provider>;
Expand Down
3 changes: 2 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export {
ResponseType,
ConnectError,
CustomTokenExchangeOptions,
TokenEndpointResponse
TokenEndpointResponse,
ClientConfiguration,
} from '@auth0/auth0-spa-js';
export { OAuthError } from './errors';