diff --git a/__tests__/auth-provider.test.tsx b/__tests__/auth-provider.test.tsx index f99c20c0..a5815629 100644 --- a/__tests__/auth-provider.test.tsx +++ b/__tests__/auth-provider.test.tsx @@ -256,6 +256,18 @@ describe('Auth0Provider', () => { ); }); + it('should call getAccessTokenSilently in the scope of the Auth0 client', async () => { + clientMock.getTokenSilently.mockReturnThis(); + const wrapper = createWrapper(); + const { waitForNextUpdate, result } = renderHook( + () => useContext(Auth0Context), + { wrapper } + ); + await waitForNextUpdate(); + const returnedThis = await result.current.getAccessTokenSilently(); + expect(returnedThis).toStrictEqual(clientMock); + }); + it('should provide a getAccessTokenWithPopup method', async () => { clientMock.getTokenWithPopup.mockResolvedValue('token'); const wrapper = createWrapper(); @@ -270,6 +282,18 @@ describe('Auth0Provider', () => { expect(token).toBe('token'); }); + it('should call getAccessTokenWithPopup in the scope of the Auth0 client', async () => { + clientMock.getTokenWithPopup.mockReturnThis(); + const wrapper = createWrapper(); + const { waitForNextUpdate, result } = renderHook( + () => useContext(Auth0Context), + { wrapper } + ); + await waitForNextUpdate(); + const returnedThis = await result.current.getAccessTokenWithPopup(); + expect(returnedThis).toStrictEqual(clientMock); + }); + it('should normalize errors from getAccessTokenWithPopup method', async () => { clientMock.getTokenWithPopup.mockRejectedValue(new ProgressEvent('error')); const wrapper = createWrapper(); diff --git a/src/auth0-provider.tsx b/src/auth0-provider.tsx index 4e75d70d..e21231fa 100644 --- a/src/auth0-provider.tsx +++ b/src/auth0-provider.tsx @@ -182,8 +182,12 @@ const Auth0Provider = ({ + client.getTokenSilently(opts) + ), + getAccessTokenWithPopup: wrappedGetToken((opts?) => + client.getTokenWithPopup(opts) + ), getIdTokenClaims: (opts): Promise => client.getIdTokenClaims(opts), loginWithRedirect: (opts): Promise =>