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

Fix issue where storeIDToken config not used by getAccessToken #1091

Merged
merged 1 commit into from
Mar 2, 2023
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
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