Skip to content

Commit

Permalink
fix(server): fix impersonation token (#1095)
Browse files Browse the repository at this point in the history
  • Loading branch information
blessanabraham committed Feb 1, 2021
1 parent 7b65203 commit 997ca43
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 6 additions & 1 deletion packages/server/__tests__/account-server.ts
Expand Up @@ -1316,6 +1316,11 @@ describe('AccountsServer', () => {
impersonationAuthorize: async (userObject, impersonateToUser) => {
return userObject.id === user.id && impersonateToUser === impersonatedUser;
},
tokenCreator: {
createToken: async () => {
return '123';
},
},
},
{}
);
Expand All @@ -1342,7 +1347,7 @@ describe('AccountsServer', () => {
);
expect(res).toEqual({
authorized: true,
tokens: { token: '001', isImpersonated: true },
tokens: { token: '123', isImpersonated: true },
user: impersonatedUser,
});
expect(createSession).toHaveBeenCalledWith(
Expand Down
5 changes: 3 additions & 2 deletions packages/server/src/accounts-server.ts
Expand Up @@ -304,13 +304,13 @@ Please set ambiguousErrorMessages to false to be able to use autologin.`
return { authorized: false };
}

const token = generateRandomToken();
const token = await this.createSessionToken(impersonatedUser);
const newSessionId = await this.db.createSession(impersonatedUser.id, token, infos, {
impersonatorUserId: user.id,
});

const impersonationTokens = await this.createTokens({
token: newSessionId,
token,
isImpersonated: true,
user,
});
Expand All @@ -323,6 +323,7 @@ Please set ambiguousErrorMessages to false to be able to use autologin.`
await this.hooks.emit(ServerHooks.ImpersonationSuccess, {
user,
impersonationResult,
sessionId: newSessionId,
});

return impersonationResult;
Expand Down

0 comments on commit 997ca43

Please sign in to comment.