Skip to content

Commit

Permalink
Use user provided params on silent login (#318)
Browse files Browse the repository at this point in the history
* Use user provided params on silent login

* Add test for custom query params

Co-authored-by: Steve Hobbs <steve.hobbs.mail@gmail.com>
  • Loading branch information
nkete and Steve Hobbs committed Jan 24, 2020
1 parent b925472 commit 6192758
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
23 changes: 23 additions & 0 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 13 additions & 5 deletions src/Auth0Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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(
Expand Down

0 comments on commit 6192758

Please sign in to comment.