mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
feat(core): add ts to interaction result (#1917)
This commit is contained in:
parent
443f45ed2e
commit
e01042cbcd
4 changed files with 34 additions and 13 deletions
|
@ -1,3 +1,4 @@
|
|||
import dayjs from 'dayjs';
|
||||
import { Context } from 'koa';
|
||||
import { InteractionResults, Provider } from 'oidc-provider';
|
||||
|
||||
|
@ -14,20 +15,31 @@ export const assignInteractionResults = async (
|
|||
// have to do it manually
|
||||
// refer to: https://github.com/panva/node-oidc-provider/blob/c243bf6b6663c41ff3e75c09b95fb978eba87381/lib/actions/authorization/interactions.js#L106
|
||||
const details = merge ? await provider.interactionDetails(ctx.req, ctx.res) : undefined;
|
||||
const ts = dayjs().unix();
|
||||
const mergedResult = {
|
||||
// Merge with current result
|
||||
...details?.result,
|
||||
...result,
|
||||
};
|
||||
|
||||
const redirectTo = await provider.interactionResult(
|
||||
ctx.req,
|
||||
ctx.res,
|
||||
{
|
||||
// Merge with current result
|
||||
...details?.result,
|
||||
...result,
|
||||
...mergedResult,
|
||||
login: mergedResult.login
|
||||
? {
|
||||
...mergedResult.login,
|
||||
// Update ts(timestamp) if the accountId is been set in result
|
||||
ts: result.login?.accountId ? ts : mergedResult.login.ts,
|
||||
}
|
||||
: undefined,
|
||||
},
|
||||
{
|
||||
mergeWithLastSubmission: merge,
|
||||
}
|
||||
);
|
||||
ctx.body = { redirectTo };
|
||||
ctx.body = { redirectTo, ts };
|
||||
};
|
||||
|
||||
export const saveUserFirstConsentedAppId = async (userId: string, applicationId: string) => {
|
||||
|
|
|
@ -97,7 +97,8 @@ describe('session -> passwordlessRoutes', () => {
|
|||
expect(interactionResult).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
expect.anything(),
|
||||
expect.objectContaining({ login: { accountId: 'id' } }),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
expect.objectContaining({ login: expect.objectContaining({ accountId: 'id' }) }),
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
@ -146,7 +147,8 @@ describe('session -> passwordlessRoutes', () => {
|
|||
expect(interactionResult).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
expect.anything(),
|
||||
expect.objectContaining({ login: { accountId: 'id' } }),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
expect.objectContaining({ login: expect.objectContaining({ accountId: 'id' }) }),
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
@ -214,7 +216,8 @@ describe('session -> passwordlessRoutes', () => {
|
|||
expect(interactionResult).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
expect.anything(),
|
||||
expect.objectContaining({ login: { accountId: 'user1' } }),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
expect.objectContaining({ login: expect.objectContaining({ accountId: 'user1' }) }),
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
@ -291,7 +294,8 @@ describe('session -> passwordlessRoutes', () => {
|
|||
expect(interactionResult).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
expect.anything(),
|
||||
expect.objectContaining({ login: { accountId: 'user1' } }),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
expect.objectContaining({ login: expect.objectContaining({ accountId: 'user1' }) }),
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
|
|
@ -223,7 +223,8 @@ describe('session -> socialRoutes', () => {
|
|||
expect(interactionResult).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
expect.anything(),
|
||||
expect.objectContaining({ login: { accountId: 'id' } }),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
expect.objectContaining({ login: expect.objectContaining({ accountId: 'id' }) }),
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
@ -309,7 +310,8 @@ describe('session -> socialRoutes', () => {
|
|||
expect(interactionResult).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
expect.anything(),
|
||||
expect.objectContaining({ login: { accountId: 'user1' } }),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
expect.objectContaining({ login: expect.objectContaining({ accountId: 'user1' }) }),
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
@ -346,7 +348,8 @@ describe('session -> socialRoutes', () => {
|
|||
expect(interactionResult).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
expect.anything(),
|
||||
expect.objectContaining({ login: { accountId: 'user1' } }),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
expect.objectContaining({ login: expect.objectContaining({ accountId: 'user1' }) }),
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
|
|
@ -111,7 +111,8 @@ describe('sessionRoutes', () => {
|
|||
expect(interactionResult).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
expect.anything(),
|
||||
expect.objectContaining({ login: { accountId: 'user1' } }),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
expect.objectContaining({ login: expect.objectContaining({ accountId: 'user1' }) }),
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
@ -180,7 +181,8 @@ describe('sessionRoutes', () => {
|
|||
expect(interactionResult).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
expect.anything(),
|
||||
expect.objectContaining({ login: { accountId: 'user1' } }),
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
expect.objectContaining({ login: expect.objectContaining({ accountId: 'user1' }) }),
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue