Skip to content

Commit

Permalink
Fixed up code + tests after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Hobbs committed Jan 26, 2020
1 parent 3733206 commit 2ef25e6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 24 deletions.
16 changes: 1 addition & 15 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1256,20 +1256,6 @@ describe('Auth0', () => {
expect(token).toBe(TEST_ACCESS_TOKEN);
});

it('acquires and releases lock when there is a cache', async () => {
const { auth0, cache, lock } = await setup();
cache.get.mockReturnValue({ access_token: TEST_ACCESS_TOKEN });

await auth0.getTokenSilently();
expect(lock.acquireLockMock).toHaveBeenCalledWith(
GET_TOKEN_SILENTLY_LOCK_KEY,
5000
);
expect(lock.releaseLockMock).toHaveBeenCalledWith(
GET_TOKEN_SILENTLY_LOCK_KEY
);
});

it('continues method execution when there is no cache available', async () => {
const { auth0, utils } = await setup();

Expand Down Expand Up @@ -1536,7 +1522,7 @@ describe('Auth0', () => {
response_mode: 'web_message',
prompt: 'none',
state: TEST_ENCODED_STATE,
nonce: TEST_RANDOM_STRING,
nonce: TEST_ENCODED_STATE,
redirect_uri: 'http://localhost',
code_challenge: TEST_BASE64_ENCODED_STRING,
code_challenge_method: 'S256',
Expand Down
17 changes: 8 additions & 9 deletions src/Auth0Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ export default class Auth0Client {
domain,
leeway,
useRefreshTokens,
cacheStrategy,
cacheLocation,
...withoutDomain
} = this.options;

return {
...withoutDomain,
...authorizeOptions,
Expand Down Expand Up @@ -388,24 +389,22 @@ export default class Auth0Client {
* @param options
*/
public async getTokenSilently(options: GetTokenSilentlyOptions = {}) {
const { ignoreCache, ...additionalOptions } = options;

options = {
const { ignoreCache, ...refreshTokenOptions } = {
audience: this.options.audience,
scope: getUniqueScopes(
this.DEFAULT_SCOPE,
this.options.scope,
options.scope
),
ignoreCache: false,
...additionalOptions
...options
};

try {
if (!ignoreCache) {
const cache = this.cache.get({
scope: options.scope,
audience: options.audience || 'default',
scope: refreshTokenOptions.scope,
audience: refreshTokenOptions.audience || 'default',
client_id: this.options.client_id
});

Expand All @@ -417,8 +416,8 @@ export default class Auth0Client {
await lock.acquireLock(GET_TOKEN_SILENTLY_LOCK_KEY, 5000);

const authResult = this.options.useRefreshTokens
? await this._getTokenUsingRefreshToken(options)
: await this._getTokenFromIFrame(options);
? await this._getTokenUsingRefreshToken(refreshTokenOptions)
: await this._getTokenFromIFrame(refreshTokenOptions);

this.cache.save({ client_id: this.options.client_id, ...authResult });

Expand Down

0 comments on commit 2ef25e6

Please sign in to comment.