diff --git a/__tests__/index.test.ts b/__tests__/index.test.ts index d9f2ebdf3..0fc1aa0b2 100644 --- a/__tests__/index.test.ts +++ b/__tests__/index.test.ts @@ -1208,6 +1208,29 @@ describe('Auth0', () => { defaultOptionsIgnoreCacheTrue.scope ); }); + it('creates correct query params when providing user specified custom query params', async () => { + const { auth0, utils } = await setup(); + + const customQueryParameterOptions = { + ...defaultOptionsIgnoreCacheTrue, + foo: 'bar' + }; + await auth0.getTokenSilently(customQueryParameterOptions); + expect(utils.createQueryParams).toHaveBeenCalledWith({ + audience: defaultOptionsIgnoreCacheTrue.audience, + client_id: TEST_CLIENT_ID, + scope: TEST_SCOPES, + response_type: TEST_CODE, + response_mode: 'web_message', + prompt: 'none', + state: TEST_ENCODED_STATE, + nonce: TEST_RANDOM_STRING, + redirect_uri: 'http://localhost', + code_challenge: TEST_BASE64_ENCODED_STRING, + code_challenge_method: 'S256', + foo: 'bar' + }); + }); it('opens iframe with correct urls', async () => { const { auth0, utils } = await setup(); await auth0.getTokenSilently(defaultOptionsIgnoreCacheTrue); diff --git a/src/Auth0Client.ts b/src/Auth0Client.ts index 1452177d2..9ad33b32a 100644 --- a/src/Auth0Client.ts +++ b/src/Auth0Client.ts @@ -332,10 +332,17 @@ export default class Auth0Client { options.scope = getUniqueScopes(this.DEFAULT_SCOPE, options.scope); try { - if (!options.ignoreCache) { + const { + audience, + scope, + ignoreCache, + ...additionalQueryParams + } = options; + + if (!ignoreCache) { const cache = this.cache.get({ - scope: options.scope, - audience: options.audience || 'default' + scope, + audience: audience || 'default' }); if (cache) { @@ -352,8 +359,9 @@ export default class Auth0Client { const code_challenge = bufferToBase64UrlEncoded(code_challengeBuffer); const authorizeOptions = { - audience: options.audience, - scope: options.scope + audience, + scope, + ...additionalQueryParams }; const params = this._getParams(