Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use user provided params on silent login #318

Merged
merged 4 commits into from
Jan 24, 2020
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
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