Skip to content

Commit

Permalink
Fix issue where storeIDToken config not used by getAccessToken (#1091)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjmcgrath authored Mar 2, 2023
2 parents 0cb8190 + 9d6c88e commit 175b9e0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ export interface NextConfig extends Pick<BaseConfig, 'identityClaimFilter'> {
login: string;
unauthorized: string;
};
session: Pick<SessionConfig, 'storeIDToken'>;
}

/**
Expand Down Expand Up @@ -565,7 +566,8 @@ export const getConfig = (params: ConfigParameters = {}): { baseConfig: BaseConf
unauthorized: baseParams.routes?.unauthorized || '/api/auth/401'
},
identityClaimFilter: baseConfig.identityClaimFilter,
organization: organization || AUTH0_ORGANIZATION
organization: organization || AUTH0_ORGANIZATION,
session: { storeIDToken: baseConfig.session.storeIDToken }
};

return { baseConfig, nextConfig };
Expand Down
2 changes: 1 addition & 1 deletion src/session/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function fromTokenSet(tokenSet: TokenSet, config: Config | NextConfig): S
});

const { id_token, access_token, scope, expires_at, refresh_token, ...remainder } = tokenSet;
const storeIDToken = 'session' in config ? config.session.storeIDToken : true;
const storeIDToken = config.session.storeIDToken;

return Object.assign(
new Session({ ...claims }),
Expand Down
5 changes: 4 additions & 1 deletion tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ describe('config params', () => {
postLogoutRedirect: '',
unauthorized: '/api/auth/401'
},
organization: undefined
organization: undefined,
session: {
storeIDToken: true
}
});
});

Expand Down
21 changes: 21 additions & 0 deletions tests/session/get-access-token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,27 @@ describe('get access token', () => {
expect(newAccessTokenScope).toBeUndefined();
});

test('should retrieve a new access token and update the session based on the storeIDToken config', async () => {
await refreshTokenExchange(withApi, 'GEbRxBN...edjnXbL', {}, 'new-token');
const baseUrl = await setup(
{ ...withApi, session: { storeIDToken: false } },
{
getAccessTokenOptions: {
refresh: true
}
}
);
const cookieJar = await login(baseUrl);
const session = await get(baseUrl, '/api/session', { cookieJar });
expect(session.idToken).toBeUndefined();
const { accessToken } = await get(baseUrl, '/api/access-token', { cookieJar });
expect(accessToken).toEqual('new-token');
const newSession = await get(baseUrl, '/api/session', {
cookieJar
});
expect(newSession.idToken).toBeUndefined();
});

test('should pass custom auth params in refresh grant request body', async () => {
const idToken = await makeIdToken({
iss: `${withApi.issuerBaseURL}/`,
Expand Down
6 changes: 4 additions & 2 deletions tests/session/session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ describe('session', () => {
expect(
fromTokenSet(new TokenSet({ id_token: await makeIdToken({ foo: 'bar', bax: 'qux' }) }), {
identityClaimFilter: ['baz'],
routes
routes,
session: { storeIDToken: true }
}).user
).toEqual({
aud: '__test_client_id__',
Expand All @@ -34,7 +35,8 @@ describe('session', () => {
expect(
fromTokenSet(new TokenSet({ id_token: await makeIdToken({ foo: 'bar' }) }), {
identityClaimFilter: ['baz'],
routes
routes,
session: { storeIDToken: true }
}).idToken
).toBeDefined();
});
Expand Down

0 comments on commit 175b9e0

Please sign in to comment.