diff --git a/__tests__/Auth0Client.test.ts b/__tests__/Auth0Client.test.ts index e222b86ce..af966b58c 100644 --- a/__tests__/Auth0Client.test.ts +++ b/__tests__/Auth0Client.test.ts @@ -661,7 +661,10 @@ describe('Auth0Client', () => { }); it('sends custom options through to the token endpoint when using an iframe', async () => { - const auth0 = setup(); + const auth0 = setup({ + custom_param: 'foo', + another_custom_param: 'bar' + }); await login(auth0, true); @@ -670,14 +673,23 @@ describe('Auth0Client', () => { state: 'MTIz' }); + mockFetch.mockResolvedValue( + fetchResponse(true, { + id_token: 'my_id_token', + refresh_token: 'my_refresh_token', + access_token: 'my_access_token', + expires_in: 86400 + }) + ); + await auth0.getTokenSilently({ ignoreCache: true, - customParam: 'hello world' + custom_param: 'hello world' }); expect( (utils.runIframe).mock.calls[0][0].includes( - 'customParam=hello%20world' + 'custom_param=hello%20world&another_custom_param=bar' ) ).toBe(true); @@ -685,19 +697,27 @@ describe('Auth0Client', () => { redirect_uri: 'my_callback_url', client_id: 'auth0_client_id', grant_type: 'authorization_code', - customParam: 'hello world', + custom_param: 'hello world', + another_custom_param: 'bar', code_verifier: '123' }); }); it('sends custom options through to the token endpoint when using refresh tokens', async () => { const auth0 = setup({ - useRefreshTokens: true + useRefreshTokens: true, + custom_param: 'foo', + another_custom_param: 'bar' }); await login(auth0, true, { refresh_token: 'a_refresh_token' }); - mockFetch.mockResolvedValueOnce( + jest.spyOn(utils, 'runIframe').mockResolvedValue({ + access_token: 'my_access_token', + state: 'MTIz' + }); + + mockFetch.mockResolvedValue( fetchResponse(true, { id_token: 'my_id_token', refresh_token: 'my_refresh_token', @@ -710,7 +730,7 @@ describe('Auth0Client', () => { const access_token = await auth0.getTokenSilently({ ignoreCache: true, - customParam: 'hello world' + custom_param: 'hello world' }); expect(JSON.parse(mockFetch.mock.calls[1][1].body)).toEqual({ @@ -718,7 +738,8 @@ describe('Auth0Client', () => { client_id: 'auth0_client_id', grant_type: 'refresh_token', refresh_token: 'a_refresh_token', - customParam: 'hello world' + custom_param: 'hello world', + another_custom_param: 'bar' }); expect(access_token).toEqual('my_access_token'); diff --git a/src/Auth0Client.ts b/src/Auth0Client.ts index 5e68d2dc7..5fd6479f4 100644 --- a/src/Auth0Client.ts +++ b/src/Auth0Client.ts @@ -82,12 +82,38 @@ const cacheFactory = (location: string) => { */ const isIE11 = () => /Trident.*rv:11\.0/.test(navigator.userAgent); +/** + * @ignore + */ +const getCustomInitialOptions = ( + options: Auth0ClientOptions +): BaseLoginOptions => { + const { + advancedOptions, + audience, + auth0Client, + authorizeTimeoutInSeconds, + cacheLocation, + client_id, + domain, + issuer, + leeway, + max_age, + redirect_uri, + scope, + useRefreshTokens, + ...customParams + } = options; + return customParams; +}; + /** * Auth0 SDK for Single Page Applications using [Authorization Code Grant Flow with PKCE](https://auth0.com/docs/api-auth/tutorials/authorization-code-grant-pkce). */ export default class Auth0Client { private cache: ICache; private transactionManager: TransactionManager; + private customOptions: BaseLoginOptions; private domainUrl: string; private tokenIssuer: string; private defaultScope: string; @@ -137,6 +163,8 @@ export default class Auth0Client { ) { this.worker = new TokenWorker(); } + + this.customOptions = getCustomInitialOptions(options); } private _url(path) { @@ -720,6 +748,7 @@ export default class Auth0Client { const tokenResult = await oauthToken( { + ...this.customOptions, ...customOptions, scope, audience, @@ -783,6 +812,7 @@ export default class Auth0Client { try { tokenResult = await oauthToken( { + ...this.customOptions, ...customOptions, audience, scope,